henry
henry

Reputation: 47

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

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.

Does anyone know why this keeps going on? My bot has been running fine for 1 month then suddenly it appears like this every once in a while, although it only affects the status of the bot, all the bot functions are fine

Upvotes: 1

Views: 2823

Answers (1)

LoahL
LoahL

Reputation: 2613

Since you start the task in on_ready, which could be called multiplie times, when on_ready is called the second time, you get this error. To prevent this, you could simply check if the task is already started:

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

Sources:

If this doesn't work for you, could you include the code of on_ready and update_fetch in your post

Upvotes: 4

Related Questions