0

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?

Dharman
  • 30,962
  • 25
  • 85
  • 135
TimKostenok
  • 52
  • 11

2 Answers2

2

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())
0stone0
  • 34,288
  • 4
  • 39
  • 64
1

Its because u tryna get attribute of coro, not coro returned object

Aboba
  • 11
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 21 '23 at 11:03
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34574807) – Chenmunka Jun 24 '23 at 12:04