From e9e81d1a55fdac6ac5b98c5aa6b1c16291026d13 Mon Sep 17 00:00:00 2001 From: Sebastian Law <44045823+SebbyLaw@users.noreply.github.com> Date: Tue, 29 Dec 2020 05:24:54 -0800 Subject: [PATCH] [commands] fully remove command when CommandRegistrationError is raised for alias --- discord/ext/commands/core.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 248a0e143..b0358ca9a 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -1145,6 +1145,7 @@ class GroupMixin: self.all_commands[command.name] = command for alias in command.aliases: if alias in self.all_commands: + self.remove_command(command.name) raise CommandRegistrationError(alias, alias_conflict=True) self.all_commands[alias] = command @@ -1177,7 +1178,12 @@ class GroupMixin: # we're not removing the alias so let's delete the rest of them. for alias in command.aliases: - self.all_commands.pop(alias, None) + cmd = self.all_commands.pop(alias, None) + # in the case of a CommandRegistrationError, an alias might conflict + # with an already existing command. If this is the case, we want to + # make sure the pre-existing command is not removed. + if cmd not in (None, command): + self.all_commands[alias] = cmd return command def walk_commands(self):