Search code examples
pythonbotstelethon

Do a task for a 1 minute interval telethon


async def main():
    me = await client.get_me()

    await client.send_message(####, 'Hello')


with client:
    client.loop.run_until_complete(main())

I want to run the code above every 1 minute, how can I achieve this?


Solution

  • Here is one solution using asyncio sleep:

    from asyncio import sleep
    
    async def main():
        while True:
            me = await client.get_me()
    
            await client.send_message(####, 'Hello')
            await sleep(60) # sleep for a min
    
    with client:
        client.loop.run_until_complete(main())