为 1 分钟间隔的电视节目做一个任务

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())

我想每 1 分钟 运行 上面的代码,我该如何实现?

这是一种使用 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())

我们使用循环,为了多次执行同一个任务,可以考虑while循环。

import asyncio


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

    while True:  # True will make sure loop will run infinite time
        await client.send_message("me", 'Hello')
        await asyncio.sleep(60)  # `.sleep` will make your code sleep for x ammout of seconds. 


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