【问题标题】:How to run scheduler so that other function works in discord.py如何运行调度程序以便其他功能在 discord.py 中工作
【发布时间】:2021-05-29 02:30:38
【问题描述】:

我认为日程安排不会干扰机器人命令,但确实如此。在我运行计划之后,假设每分钟一次,它会阻止我的机器人中的其他功能。我正在寻找一种解决方案来通过调度程序运行 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函数检测消息。

感谢您的帮助

【问题讨论】:

  • 你确定是因为schedule
  • func 定义在哪里?
  • 没错!你认为你是从这里得到的吗?
  • 我在问您在使用任务时是否需要更多帮助?请先阅读文档,然后再回来询问。

标签: python discord.py schedule


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-06-26
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    • 2015-11-17
    • 2022-12-23
    相关资源
    最近更新 更多