From bbf9a42f8715e58f5c6f085244a862ef29a59192 Mon Sep 17 00:00:00 2001 From: Vexs Date: Fri, 19 Apr 2019 18:00:23 -0500 Subject: [PATCH] [commands] Add Command.parents Make command.root_parent use new command.parents property --- discord/ext/commands/core.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index c70ade1ef..5779717c3 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -503,6 +503,27 @@ class Command(_BaseCommand): return ' '.join(reversed(entries)) + @property + def parents(self): + """Retrieves the parents of this command. + + .. versionadded:: 1.1.0 + + If the command has no parents then it returns an empty :class:`list`. + + For example in commands ``?a b c test``, + the parents are ``[c, b, a]``. + + + """ + entries = [] + command = self + while command.parent is not None: + command = command.parent + entries.append(command) + + return entries + @property def root_parent(self): """Retrieves the root parent of this command. @@ -512,16 +533,9 @@ class Command(_BaseCommand): For example in commands ``?a b c test``, the root parent is ``a``. """ - entries = [] - command = self - while command.parent is not None: - command = command.parent - entries.append(command) - - if len(entries) == 0: + if not self.parent: return None - - return entries[-1] + return self.parents[-1] @property def qualified_name(self):