如何 运行 调度程序以便其他功能在 discord.py 中工作

How to run scheduler so that other function works in discord.py

我认为时间表不会干扰机器人命令,但它会。在我 运行 一个时间表之后,假设每隔一分钟,它会阻止我的机器人中的其他功能。我正在寻找 运行 通过调度程序完成 1 个简单任务的解决方案(我正在使用 this 调度模块)并保留所有主要机器人功能 - 任何命令或事件。

示例:

@client.event
async def on_message(message):
    if message.author.id == xxxxx:
        print("im working")

def test():
    print("hello")

job = schedule.every().second.do(test)

while 1:
    schedule.run_pending()
 

我想要 运行 test 功能,并且能够同时通过 on_message 功能检测消息。

感谢您的帮助

Discord.py 有一个功能,see the full documentation here。这里有一个简短的例子:

from discord.ext import tasks

@tasks.loop(seconds=5)
async def foo():
   print('This function runs every 5 Seconds')