问题
How can I have more than one loop running ate the same time using the same function but using different parameters like:
@tasks.loop(seconds = 10)
async def loop(name):
Print(name)
loop.start("Jon")
loop.start("Joseph")
Is this how u pass parameters to loops?
回答1:
You need to create a new Loop
object for each loop. You can do this by using regular function calling repeatedly instead of the decorator:
async def loop(name):
print(name)
names = ["Jon", "Joseph"]
loops = {name: tasks.loop(seconds=10)(name) for name in names}
来源:https://stackoverflow.com/questions/62440735/discord-py-more-than-one-tasks-loop-at-the-same-time