如何获得在BotFather中注册的所有漫游器的列表? [英] How can I get a list of all bots registered with BotFather?

查看:153
本文介绍了如何获得在BotFather中注册的所有漫游器的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是在通过API在电报客户端中进行授权后,获取所有用户漫游器的列表.我在文档中查找了一种特定的方法,但是没有找到它.有人可以告诉我该怎么做吗,有可能吗?

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?

推荐答案

不幸的是,我认为没有直接的API.但是,请考虑自动与BotFather进行交互,以编程方式收集列表.

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.

这是 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()

运行示例将打印botfather中的所有bot:

a sample run would print all the bots from botfather:

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

这篇关于如何获得在BotFather中注册的所有漫游器的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆