我的任务是获取所有用户机器人的列表,通过API在电报客户端进行授权。我在文档中查找了特定的方法,但没有找到。有人能告诉我这是怎么做的吗?这是可能的吗?
发布于 2020-06-05 19:16:49
不幸的是,我不认为有一个直接的API可以解决这个问题。但是可以考虑自动化与BotFather的交互,以编程方式收集列表。
以下是Telethon中的示例脚本
from telethon import TelegramClient, events
API_ID = ...
API_HASH = "..."
client = TelegramClient('session', api_id=API_ID, api_hash=API_HASH)
bots_list = []
@client.on(events.MessageEdited(chats="botfather"))
@client.on(events.NewMessage(chats="botfather"))
async def message_handler(event):
if 'Choose a bot from the list below:' in event.message.message:
last_page = True
for row in event.buttons:
for button in row:
if button.text == '»':
last_page = False
await button.click()
elif button.text != '«':
bots_list.append(button.text)
if last_page:
print(bots_list)
await client.disconnect()
exit(0)
async def main():
await client.send_message('botfather', '/mybots')
with client:
client.loop.run_until_complete(main())
client.run_until_disconnected()一个简单的运行将会打印所有的bot:
['@xxxxxBot', '@xxxxxBot', … ]https://stackoverflow.com/questions/62209102
复制相似问题