I am trying to build a python script which requires login with multiple telegram accounts. I don’t want to run a separate script for each account.I am using TELETHON. I know that there is something like create_new_connection
in telethon, but I don’t know how it can help me. Is there a way by which I can use just one python script and login using several accounts..?
(If possible please include the code snippet to use in your answer)
Question posted in Telegram API
A comprehensive official documentation can be found here.
A comprehensive official documentation can be found here.
2
Answers
Create multiple clients
When you create a client, the first parameter you pass is the session file name. Different sessions can have different clients logged in, so it’s enough to create multiple clients each with a different session file name for them to use different accounts:
Of course, you could also use a list to trivially support an arbitrary number of clients. What you do with these clients is up to you, although you will generally just take advantage of
asyncio
as explained in the Python documentation – Running Tasks Concurrently:You could, of course, run separate code for each, use conditionals, etc. It depends a lot on your needs, and what these are will influence your design too.