I am trying to run a task.loop multiple times with a Discord bot, however this is not working as the loop is already running.
I found this answer in another question:
async def loop(name):
print(name)
names = ["Jon", "Joseph"]
loops = {name: tasks.loop(seconds=10)(name) for name in names}
However, I can't figure it out. I don't understand how to automatically create a new loop from this, I always get this error with this program:
Traceback (most recent call last):
File "main.py", line 11, in <module>
loops = {name: tasks.loop(seconds=10)(name) for name in names}
File "main.py", line 11, in <dictcomp>
loops = {name: tasks.loop(seconds=10)(name) for name in names}
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/tasks/__init__.py", line 506, in decorator
return Loop(func, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/tasks/__init__.py", line 76, in __init__
raise TypeError('Expected coroutine function, not {0.__name__!r}.'.format(type(self.coro)))
TypeError: Expected coroutine function, not 'str'.
I copied the code to try it out and pasted it into a new program, this now looks like this:
import discord
from discord.ext import tasks
async def loop(name):
print(name)
names = ["Jon", "Joseph"]
loops = {name: tasks.loop(seconds=10)(name) for name in names}#What exactly does this line do?
What do I have to change so that this error goes away and the loop can be executed multiple times?