#cant disable cog

1 messages · Page 1 of 1 (latest)

haughty topaz
#

if i make task.loop for my cog and then stop/delete this cog It still continues to be updated
And if I reload the cog, it starts task.loop 2 times
Because of this, my cog is updated about 2 times per second after I have restarted many times, as well as a very strong spam in the console about rate limits, as a result, I can't stop it in any way because I'm not at home and if I turn off the bot, I won't be able to turn it back on

any ideas how i cab make thing in my command when i restart/delete cog it stops current task.loop?

daring oak
#

You need to stop/cancel the task in cog_unload or something

haughty topaz
# daring oak You need to stop/cancel the task in cog_unload or something

I thought about doing a check on what kind of cog it is, and if it's a cog with task.loop, then it was disabled in the script, but then the command is not automated, because you have to manually check what kind of cog it is, and every time you create a new task.loop, when you create a new task.loop, you will need to change the command

twin burrow
daring oak
#

that's for the extension yes

#

cog_unload is for inside the cog

haughty topaz
daring oak
#

Are you creating tasks dynamically

haughty topaz
daring oak
#

Wdym add to command

haughty topaz
daring oak
#

Most people do something like this

class MyCog(Cog):
    def __init__(self, ...):
        # START TASK when loading
        self.my_task.start()

    def cog_unload(self):
        # STOP TASK when unloading
        self.my_task.stop()

    @tasks.loop(...)
    async def my_task(self):
        ...
haughty topaz
twin burrow
#

its in docs

#

how you handle cancelation etc

twin burrow
daring oak
#

^^

twin burrow
#

when you do .unload or .reload extension

daring oak
#

You can get the cog and stop the task manually if you want but why

cog = bot.get_cog("ClassName")
cog.my_task.stop()

Not create a new instance, that'll run everything again

haughty topaz
daring oak
#

=docs label:Cogs

shadow nicheBOT
daring oak
#

=docs tasks