I know there's an answer out there. I have been searching for some time couldn't find it. Please look at the code below.
import logging
import asyncio
import time
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
level=logging.WARNING)
from telethon import TelegramClient, events
api_id = '**'
api_hash = '**'
client = TelegramClient('anon', api_id, api_hash)
async def check_message_exists(event):
time.sleep(5)
print(event, time.time())
@client.on(events.NewMessage(chats = [-100**]))
async def my_event_handler(event):
asyncio.ensure_future(check_message_exists('Got message'))
client.start()
client.run_until_disconnected()
I want my_event_handler() to run without waiting for the check_message_exists() to end. Thanks in advance.