How can I get a list of all bots registered with BotFather?

北城以北 提交于 2020-06-28 03:41:40

问题


My task is to get a list of all user bots, after authorization in the telegram client through the API. I looked in the documentation for a specific method, but did not find it. Can someone tell me how this can be done, and is it possible at all?


回答1:


I don't think there's a direct API for that unfortunately. But consider automating the interaction with the BotFather to gather the list programmatically.

Here is a sample script in 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()

a sample run would print all the bots from botfather:

['@xxxxxBot', '@xxxxxBot', … ]


来源:https://stackoverflow.com/questions/62209102/how-can-i-get-a-list-of-all-bots-registered-with-botfather

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!