May*_*ank 3 python telegram python-telegram-bot telegram-bot telethon
我正在尝试构建一个需要使用多个电报帐户登录的 python 脚本。我不想为每个帐户运行单独的脚本。我正在使用 TELETHON。我知道create_new_connection在 Telethon中有类似的东西,但我不知道它如何帮助我。有没有一种方法可以让我只使用一个 python 脚本并使用多个帐户登录..?(如果可能,请包含要在您的答案中使用的代码片段)
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:
user1 = TelegramClient('user1', api_id, api_hash)
user2 = TelegramClient('user2', api_id, api_hash)
Run Code Online (Sandbox Code Playgroud)
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:
user1 = TelegramClient('user1', api_id, api_hash)
user2 = TelegramClient('user2', api_id, api_hash)
Run Code Online (Sandbox Code Playgroud)
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.
| 归档时间: |
|
| 查看次数: |
2939 次 |
| 最近记录: |