问题
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