简体   繁体   English

Discord tasks.loop,任务不循环

[英]Discord tasks.loop, task doesn't loop

I'm working on a discord bot, and I need something to loop every 10 seconds.我正在开发一个不和谐的机器人,我需要每 10 秒循环一次。 I've tried following some tutorials, but it doesn't seem to be working.我试过遵循一些教程,但它似乎不起作用。 Here's my code:这是我的代码:

import discord
from discord.ext import tasks, commands
import asyncio
import passwords


client = commands.Bot(command_prefix = '.');



@tasks.loop(seconds=10)
async def name_of_function():
    print("looped")


client.run(passwords.token)

The token and such are working fine, I just have them in another file.令牌等工作正常,我只是将它们放在另一个文件中。 When I run this, nothing happens.当我运行它时,没有任何反应。 It never prints looped , and I've been letting it run for up to 10 minutes.它从不打印looped ,我一直让它运行长达 10 分钟。 What am I doing wrong, and why won't this loop?我做错了什么,为什么这个循环不会?

You need to actually start the loop as well, using name_of_function.start() .您还需要使用name_of_function.start()实际启动循环。 Make sure to put this before client.run() , as otherwise it will never be called either.确保将它放在client.run()之前,否则它将永远不会被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM