sy1vi3
sy1vi3

Reputation: 181

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?

Upvotes: 0

Views: 389

Answers (1)

stijndcl
stijndcl

Reputation: 5651

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.

Upvotes: 1

Related Questions