skip to Main Content

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?

2

Answers


  1. 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())
    
    Login or Signup to reply.
  2. Its because u tryna get attribute of coro, not coro returned object

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search