Issue
For the sake of studying the capabilities of the Telegram API, the question arose, how to get the @username of a bot in a telegram using aiogram?
I tried username = bot.get_me().username
but gives the following error:
AttributeError: 'coroutine' object has no attribute 'username'
How can this be fixed?
Solution
You can get the username of the bot by calling get_me
on the Bot
object.
The returned objects hold the username
you are looking for.
Example code:
async def main():
bot = Bot(token='859163076:AAEjLUL8Lx67blablalblalblalbal')
info = await bot.get_me();
name = info.username
print(name)
asyncio.run(main())
Answered By - 0stone0
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.