Discord py more than one tasks.loop at the same time?

柔情痞子 提交于 2021-02-11 13:30:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!