I need to run multiple Telegram accounts (that all use the same message handler) using telethon.
Exactly, I need to:
- run a function (one time per account)
- run the handler (forever)
This is the code now, I just need to run it with more than one client. I have a list of accounts, and I must use that.
async def main(client):
me = await client.get_me()
print("Working with", me.first_name)
await client.send_message("@example", "example")
client = TelegramClient(f'telegram_session', account["API_ID"], account["API_HASH"])
client.add_event_handler(handler, events.NewMessage())
with client:
client.start()
client.loop.run_until_complete(main(client))
client.run_until_disconnected()
2
Answers
I have a quick look at the library you are using, it is based on asynio. I think you should to do something like this
P.S i found answer here stackoverflow
you can do something like this.