diff options
| author | Vexs <[email protected]> | 2019-04-19 18:00:23 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-04-20 16:59:53 -0400 |
| commit | bbf9a42f8715e58f5c6f085244a862ef29a59192 (patch) | |
| tree | b00825bf9f930b960cb82294de8a6a71f89cdd0e | |
| parent | [commands] Add custom exception classes for built-in checks (diff) | |
| download | discord.py-bbf9a42f8715e58f5c6f085244a862ef29a59192.tar.xz discord.py-bbf9a42f8715e58f5c6f085244a862ef29a59192.zip | |
[commands] Add Command.parents
Make command.root_parent use new command.parents property
| -rw-r--r-- | discord/ext/commands/core.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index c70ade1e..5779717c 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -504,13 +504,17 @@ class Command(_BaseCommand): return ' '.join(reversed(entries)) @property - def root_parent(self): - """Retrieves the root parent of this command. + 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]``. - If the command has no parents then it returns ``None``. - For example in commands ``?a b c test``, the root parent is - ``a``. """ entries = [] command = self @@ -518,10 +522,20 @@ class Command(_BaseCommand): command = command.parent entries.append(command) - if len(entries) == 0: - return None + return entries - return entries[-1] + @property + def root_parent(self): + """Retrieves the root parent of this command. + + If the command has no parents then it returns ``None``. + + For example in commands ``?a b c test``, the root parent is + ``a``. + """ + if not self.parent: + return None + return self.parents[-1] @property def qualified_name(self): |