diff options
author | 2021-02-18 22:04:27 +0000 | |
---|---|---|
committer | 2021-02-18 22:04:27 +0000 | |
commit | c7de5a2577b4f2975b3fab683f2d7459c5bda636 (patch) | |
tree | 3be3659955961f5c56f7b8f01d2834f2c41770fb /bot/group.py | |
parent | Add root alias support for commands (diff) |
Extend root aliases to support commands.Group
Diffstat (limited to 'bot/group.py')
-rw-r--r-- | bot/group.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/bot/group.py b/bot/group.py new file mode 100644 index 00000000..77092adf --- /dev/null +++ b/bot/group.py @@ -0,0 +1,18 @@ +from discord.ext import commands + + +class Group(commands.Group): + """ + A `discord.ext.commands.Group` subclass which supports root aliases. + + A `root_aliases` keyword argument is added, which is a sequence of alias names that will act as + top-level commands rather than being aliases of the command's group. It's stored as an attribute + also named `root_aliases`. + """ + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.root_aliases = kwargs.get("root_aliases", []) + + if not isinstance(self.root_aliases, (list, tuple)): + raise TypeError("Root aliases of a command must be a list or a tuple of strings.") |