aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Law <[email protected]>2020-12-29 05:24:54 -0800
committerGitHub <[email protected]>2020-12-29 08:24:54 -0500
commite9e81d1a55fdac6ac5b98c5aa6b1c16291026d13 (patch)
treed254c355479b5a811a2b6d773e756189aaa6505f
parent[commands] Correct concurrency never releasing during prepare call (diff)
downloaddiscord.py-e9e81d1a55fdac6ac5b98c5aa6b1c16291026d13.tar.xz
discord.py-e9e81d1a55fdac6ac5b98c5aa6b1c16291026d13.zip
[commands] fully remove command when CommandRegistrationError is raised for alias
-rw-r--r--discord/ext/commands/core.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index 248a0e14..b0358ca9 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):