I get this exception: "Exception has occurred: AttributeError __aenter__" in line async with bot:
. (I entered the token). Please help
import asyncio
import telegram
async def main():
bot = telegram.Bot("token")
async with bot:
print(await bot.get_me())
if __name__ == '__main__':
asyncio.run(main())
I found this code here: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Introduction-to-the-API
3
Answers
Probobly that exception comming because you installed python-telegram-bot version 13.x.
try to:
for check that, and if that true you have to make
because only unstable version use async.
Think that’s because you installed v13 (pip install python-telegram-bot) and the example you are looking at is from the v20 Github wiki.
Head over here for a quick start guide for v13 wrapper: https://github.com/python-telegram-bot/v13.x-wiki/wiki/Extensions-%E2%80%93-Your-first-Bot
You can replace
print(bot.get_me())
with
async with bot: print(await bot.get_me())
This is how I solved my problem.