Browse Source

[commands] fully remove command when CommandRegistrationError is raised for alias

pull/6221/head
Sebastian Law 4 years ago
committed by GitHub
parent
commit
e9e81d1a55
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      discord/ext/commands/core.py

8
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):

Loading…
Cancel
Save