简体   繁体   中英

Discord tasks.loop, task doesn't loop

I'm working on a discord bot, and I need something to loop every 10 seconds. 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. 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() . Make sure to put this before client.run() , as otherwise it will never be called either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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