Discord.py引发运行错误('任务已启动且未完成。')

2022-02-26 00:00:00 python discord bots discord.py

问题描述

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 94, in on_ready
    update_fetch.start()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/tasks/__init__.py", line 205, in start

raise RuntimeError('Task is already launched and is not completed.')

RuntimeError: Task is already launched and is not completed.

有人知道为什么会一直这样吗?我的BOT已经正常运行了1个月,然后突然间突然出现这样的情况,虽然它只影响BOT的状态,但是BOT的所有功能都是正常的


解决方案

由于您在on_ready中启动任务,可以多次调用,当第二次调用on_ready时,您会收到此错误。 要避免这种情况,您只需检查任务是否已启动:

#change update_fetch.start() to:
if not update_fetch.is_running():
    update_fetch.start() 

来源:

  • on_ready
  • is_running

如果这对您不起作用,请在您的帖子中包含on_readyupdate_fetch的代码

相关文章