From 70f4b0b716ce9e42d325fa59b61f3bdc74a70651 Mon Sep 17 00:00:00 2001 From: bobloy Date: Fri, 23 Oct 2020 11:36:51 -0400 Subject: [PATCH] Check for unload and cancel announce task properly. --- announcedaily/__init__.py | 2 +- announcedaily/announcedaily.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/announcedaily/__init__.py b/announcedaily/__init__.py index 8cc69d5..f1db8c0 100644 --- a/announcedaily/__init__.py +++ b/announcedaily/__init__.py @@ -6,4 +6,4 @@ from .announcedaily import AnnounceDaily def setup(bot: Red): daily = AnnounceDaily(bot) bot.add_cog(daily) - bot.loop.create_task(daily.check_day()) + daily.announce_task = bot.loop.create_task(daily.check_day()) diff --git a/announcedaily/announcedaily.py b/announcedaily/announcedaily.py index aa50e6c..fb31b89 100644 --- a/announcedaily/announcedaily.py +++ b/announcedaily/announcedaily.py @@ -1,6 +1,8 @@ import asyncio import random +from asyncio import Task from datetime import datetime, timedelta +from typing import Optional import discord from redbot.core import Config, checks, commands @@ -38,10 +40,16 @@ class AnnounceDaily(Cog): self.config.register_global(**default_global) self.config.register_guild(**default_guild) + self.announce_task = None + async def red_delete_data_for_user(self, **kwargs): """Nothing to delete""" return + def __unload(self): + if self.announce_task is not None: + self.announce_task.cancel() + async def _get_msgs(self): return DEFAULT_MESSAGES + await self.config.messages()