From c7de5a2577b4f2975b3fab683f2d7459c5bda636 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 18 Feb 2021 22:04:27 +0000 Subject: Extend root aliases to support commands.Group --- bot/group.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 bot/group.py (limited to 'bot/group.py') 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.") -- cgit v1.2.3 From 6c1b715bae96980309af3b38a5ff6cad6ce49f95 Mon Sep 17 00:00:00 2001 From: ChrisJL Date: Thu, 11 Mar 2021 18:01:22 +0000 Subject: Update docstring to refer to groups rather than commands Co-authored-by: Shivansh-007 <69356296+Shivansh-007@users.noreply.github.com> --- bot/group.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/group.py') diff --git a/bot/group.py b/bot/group.py index 77092adf..a7bc59b7 100644 --- a/bot/group.py +++ b/bot/group.py @@ -6,7 +6,7 @@ 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 + top-level groups rather than being aliases of the command's group. It's stored as an attribute also named `root_aliases`. """ @@ -15,4 +15,4 @@ class Group(commands.Group): 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.") + raise TypeError("Root aliases of a group must be a list or a tuple of strings.") -- cgit v1.2.3