#Help with @tasks.loop

1 messages · Page 1 of 1 (latest)

brave iron
#

I'm having an issue where this code runs before the bot connects to discord causing

AttributeError: 'NoneType' object has no attribute 'invites'

when it gets to await guild.invites().

I tried catching the AttributeError but it still broke the loop.
The only solution I've found is to load the cog using load_extension() after the bot has already connected to discord. Is there a way I can have that load after the bot has connected or not break the loop when I catch the exception?

gentle ether
#

That's normal. You need to create a before_loop that consists of await self.bot.wait_until_ready()

#

that way the task won't actually make it's first -run until the bot is fully ready to go

craggy daggerBOT
#
background_task.py

An example showing how to regularly run a task in the background.

brave iron
#

I see

#

Let me add that

#

Thanks for the help that worked