Skip to content

Commit fe45f61

Browse files
authored
Add commands.Cog.get_commands
1 parent ca1a76c commit fe45f61

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

discord/ext/commands/cog.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import discord
2828
from ...cog import Cog
2929

30-
from typing import Any, Callable, Generator, TYPE_CHECKING, TypeVar, Type
30+
from typing import Any, Callable, Generator, TYPE_CHECKING, TypeVar, Type, Union
3131

3232
from ...commands import ApplicationCommand
3333

@@ -67,3 +67,16 @@ def walk_commands(self) -> Generator[Command, None, None]:
6767
yield command
6868
if isinstance(command, GroupMixin):
6969
yield from command.walk_commands()
70+
71+
def get_commands(self) -> List[Union[ApplicationCommand, Command]]:
72+
r"""
73+
Returns
74+
--------
75+
List[Union[:class:`~discord.ApplicationCommand`, :class:`.Command`]]
76+
A :class:`list` of commands that are defined inside this cog.
77+
78+
.. note::
79+
80+
This does not include subcommands.
81+
"""
82+
return [c for c in self.__cog_commands__ if isinstance(c, (ApplicationCommand, Command)) and c.parent is None]

0 commit comments

Comments
 (0)