mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +00:00
[commands] Fix bug in behaviour in the cog inspection methods.
This commit is contained in:
parent
7d877e9067
commit
ab8e7b7732
@ -156,18 +156,23 @@ class Cog(metaclass=CogMeta):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def get_commands(self):
|
def get_commands(self):
|
||||||
r"""Returns a :class:`tuple` of :class:`.Command`\s and its subclasses that are
|
r"""Returns a :class:`list` of :class:`.Command`\s that are
|
||||||
defined inside this cog.
|
defined inside this cog.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
This does not include subcommands.
|
||||||
"""
|
"""
|
||||||
return self.__cog_commands__
|
return [c for c in self.__cog_commands__ if c.parent is None]
|
||||||
|
|
||||||
def walk_commands(self):
|
def walk_commands(self):
|
||||||
"""An iterator that recursively walks through this cog's commands and subcommands."""
|
"""An iterator that recursively walks through this cog's commands and subcommands."""
|
||||||
from .core import GroupMixin
|
from .core import GroupMixin
|
||||||
for command in self.__cog_commands__:
|
for command in self.__cog_commands__:
|
||||||
yield command
|
if command.parent is None:
|
||||||
if isinstance(command, GroupMixin):
|
yield command
|
||||||
yield from command.walk_commands()
|
if isinstance(command, GroupMixin):
|
||||||
|
yield from command.walk_commands()
|
||||||
|
|
||||||
def get_listeners(self):
|
def get_listeners(self):
|
||||||
"""Returns a :class:`list` of (name, function) listener pairs that are defined in this cog."""
|
"""Returns a :class:`list` of (name, function) listener pairs that are defined in this cog."""
|
||||||
|
@ -142,7 +142,7 @@ Inspection
|
|||||||
Since cogs ultimately are classes, we have some tools to help us inspect certain properties of the cog.
|
Since cogs ultimately are classes, we have some tools to help us inspect certain properties of the cog.
|
||||||
|
|
||||||
|
|
||||||
To get a :class:`tuple` of commands, we can use :meth:`.Cog.get_commands`. ::
|
To get a :class:`list` of commands, we can use :meth:`.Cog.get_commands`. ::
|
||||||
|
|
||||||
>>> cog = bot.get_cog('Greetings')
|
>>> cog = bot.get_cog('Greetings')
|
||||||
>>> commands = cog.get_commands()
|
>>> commands = cog.get_commands()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user