0

So I am learning the telethon library for Pythonm but right in the beggining I've ran into the error:

    /Users/user1/Desktop/TelegramBot/main.py:8: RuntimeWarning: coroutine 'UserMethods.get_me' was never awaited
  print(client.get_me())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Running the following code:

import decouple
from telethon import TelegramClient


client = TelegramClient('testSesh', decouple.config('API_ID_TEST'), decouple.config('API_HASH_TEST'))
client.start()

print(client.get_me())

I have read the basic documentation for this module but I wasn't able to find the correct solution. Please, guys, help me :/

Thank you.

  • This should help https://stackoverflow.com/questions/54441424/learning-asyncio-coroutine-was-never-awaited-warning-error – svex99 Sep 18 '22 at 16:41

1 Answers1

0

You need to use await:

import decouple
from telethon import TelegramClient

client = TelegramClient('testSesh', decouple.config('API_ID_TEST'), decouple.config('API_HASH_TEST'))

async def main():
    await client.start()
    print(await client.get_me())

client.loop.run_until_complete(main())

start() is special-cased in v1 to not need the await but it's generally better if you write all your code inside an async def and not rely on this magic.

Lonami
  • 5,945
  • 2
  • 20
  • 38
  • Oh, thank you so much for your advice! It indeed has worked out for me, and seemingly, all I need now is to brush up on some async coding. – Stanford Martinez Sep 29 '22 at 10:35