hi i made a telegram auto-messaging bot using python but it only sends messages when i run it i need your help on how to loop it.
import sys
from telethon import TelegramClient
import time
import datetime
starttime = time.time()
api_id = #api id
api_hash = '#api hash'
groups = ['#groups ']
failcount = 0;
while True:
with TelegramClient('anon', api_id, api_hash) as client:
for x in groups:
try:
client.loop.run_until_complete(client.send_message(x, '#message'))
except:
print(x, sys.exc_info()[0])
failcount == 1
print(datetime.datetime.now(), str(failcount/len(groups) * 100) + '%')
time.sleep(10800 - ((time.time()- starttime) % 10800))
3
Answers
Well i dont know much about that but if the last print is the messsage you can always try putting it into the loop.
that’s obvious lmao delete all this and read the docs.
you start a file like this:
import things you need
to send a message use
oh and failcount should be += 1 (failcount = failcount + 1)
You actually only need to make login once. Here is an working example:
The loop above will send messages forever, but, you can add
if else
to break the loop.