Reputation: 9205
I'm trying to add a background task to my cog in Discord.py, but the task isn't running.
The cog:
class ComicPoster(Cog):
def __init__(self, bot):
self.bot: Bot = bot
migrate()
@tasks.loop(seconds=5)
async def comic_update(self):
print('asdf')
log.info('Updating all comics')
The rest of the cog works (event listeners, commands, etc), but the task never runs for some reason. How can I get it to run?
Upvotes: 0
Views: 278
Reputation: 136
You need to start the task. You can do this in the constructor (__init__
).
Here is what it should look like:
def __init__(self, bot):
self.bot: Bot = bot
migrate()
# the new line of code
self.comic_update.start()
The self.comic_update.start()
starts that task and it will loop every five seconds now.
Upvotes: 1