From f4bec507c111b22ea4303e9fdb02f15c11fd025a Mon Sep 17 00:00:00 2001 From: iDutchy Date: Wed, 30 Dec 2020 18:52:15 -0600 Subject: [PATCH] attempt at cog aliases --- discord/ext/commands/bot.py | 7 +++++++ discord/ext/commands/cog.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 3fcfd808..f4a3918d 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -529,6 +529,9 @@ class BotBase(GroupMixin): cog = cog._inject(self) self.__cogs[cog.__cog_name__] = cog + if cog.aliases: + for alias in cog.aliases: + self.__cogs[alias] = cog def get_cog(self, name): """Gets the cog instance requested. @@ -567,6 +570,10 @@ class BotBase(GroupMixin): if cog is None: return + if cog.aliases: + for alias in cog.aliases: + self.__cogs.pop(alias) + help_command = self._help_command if help_command and help_command.cog is cog: help_command.cog = None diff --git a/discord/ext/commands/cog.py b/discord/ext/commands/cog.py index 774f5317..5430852e 100644 --- a/discord/ext/commands/cog.py +++ b/discord/ext/commands/cog.py @@ -98,6 +98,11 @@ class CogMeta(type): attrs['__cog_name__'] = kwargs.pop('name', name) attrs['__cog_settings__'] = command_attrs = kwargs.pop('command_attrs', {}) + aliases = kwargs.pop('aliases', []) + if not isinstance(aliases, list): + raise TypeError("Cog aliases must be a list, not a {0}".format(type(aliases))) + attrs['aliases'] = aliases + description = kwargs.pop('description', None) if description is None: description = inspect.cleandoc(attrs.get('__doc__', ''))