Python 如何设置多个计划循环?不和谐

Python 如何设置多个计划循环?不和谐,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,我正试图每小时发布一次通知,并将在活动开始前5分钟通知角色。在我的代码中,我使用秒设置它,这样我就可以测试它了。我正在使用@tasks.loop,但在第一次发布后,时间不再同步 我还尝试使用“while和datetime”,它可以工作,但它阻止了我所有的命令 以下是我的任务循环的代码: @tasks.loop(seconds=55) async def start(): message_channel = client.get_channel(748017692505800774)

我正试图每小时发布一次通知,并将在活动开始前5分钟通知角色。在我的代码中,我使用秒设置它,这样我就可以测试它了。我正在使用@tasks.loop,但在第一次发布后,时间不再同步

我还尝试使用“while和datetime”,它可以工作,但它阻止了我所有的命令

以下是我的任务循环的代码:

@tasks.loop(seconds=55)
async def start():
    message_channel = client.get_channel(748017692505800774)
    t = dt.datetime.now()
    now = t.strftime('%I:%M:%S %p')
    await message_channel.send(f'5 minutes until clock announcement. {now} <@&748048926032003164>')

@tasks.loop(seconds=60)
async def finish():
    message_channel = client.get_channel(748017692505800774)
    t = dt.datetime.now()
    now = t.strftime('%I:%M:%S %p')
    await message_channel.send(f'The time now is **{now}** <@&748048926032003164>')

@client.event
async def on_ready():
    start.start()
    finish.start()
@tasks.loop(秒=55)
异步def start():
message_channel=client.get_channel(748017692505800774)
t=dt.datetime.now()
now=t.strftime(“%I:%M:%S%p”)
等待消息_channel.send(在时钟广播前5分钟。{now}')
@tasks.loop(秒=60)
异步def finish():
message_channel=client.get_channel(748017692505800774)
t=dt.datetime.now()
now=t.strftime(“%I:%M:%S%p”)
等待消息\u channel.send(现在的时间是**{now}**)
@客户端事件
_ready()上的异步定义:
start.start()
finish.start()

您需要在循环之前添加一个
,这样它将等待到所需的时间,然后启动。然后它将根据定义中的时间循环
@tasks.loop(小时=2)

您的任务应该是这样的,通过
timer.start()调用它

@tasks.loop(小时=2)
异步定义计时器():
message_channel=client.get_channel(748017692505800774)
t=dt.datetime.now()
now=t.strftime(“%I:%M:%S%p”)
等待消息_channel.send(在时钟广播前5分钟。{now}')
等待asyncio.sleep(5*60)#等待5分钟并再次发送
等待消息\u channel.send(现在的时间是**{now}**)
@循环前定时器
异步def before_timer():
对于范围(60)内的,它将循环等待,直到秒为零
t=dt.datetime.now()
now=t.strftime(“%S”)
如果现在==“00”:
打破
等待asyncio.sleep(1)