From b17fb67341e474d58164a15d2ae4f913f360f7a0 Mon Sep 17 00:00:00 2001 From: Sebastian Law Date: Wed, 20 Jul 2022 19:31:14 -0700 Subject: [PATCH] [commands] Unload cog when command registration fails in _inject --- discord/ext/commands/cog.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/discord/ext/commands/cog.py b/discord/ext/commands/cog.py index 28cb9e9ec..ec01937aa 100644 --- a/discord/ext/commands/cog.py +++ b/discord/ext/commands/cog.py @@ -459,7 +459,10 @@ class Cog(metaclass=CogMeta): for to_undo in self.__cog_commands__[:index]: if to_undo.parent is None: bot.remove_command(to_undo.name) - raise e + try: + await maybe_coroutine(self.cog_unload) + finally: + raise e # check if we're overriding the default if cls.bot_check is not Cog.bot_check: