Skip to content

Commit dbaf8ff

Browse files
committed
fix: walk_commands()
1 parent 105a3cc commit dbaf8ff

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

discord/cog.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import discord.utils
3434
from . import errors
35-
from .commands import _BaseCommand, ApplicationCommand, ApplicationContext
35+
from .commands import _BaseCommand, ApplicationCommand, ApplicationContext, SlashCommandGroup
3636

3737
__all__ = (
3838
'CogMeta',
@@ -275,8 +275,13 @@ def walk_commands(self) -> Generator[ApplicationCommand, None, None]:
275275
A command or group from the cog.
276276
"""
277277
for command in self.__cog_commands__:
278-
if command.parent is None:
279-
yield command
278+
if isinstance(command, SlashCommandGroup):
279+
for subcommand in command.subcommands:
280+
if subcommand.parent is not None:
281+
for sub_subcommand in subcommand.subcommands:
282+
yield sub_subcommand
283+
else:
284+
yield subcommand
280285

281286
def get_listeners(self) -> List[Tuple[str, Callable[..., Any]]]:
282287
"""Returns a :class:`list` of (name, function) listener pairs that are defined in this cog.

discord/commands/core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ def qualified_name(self) -> str:
495495
else:
496496
return self.name
497497

498+
def __str__(self) -> str:
499+
return self.qualified_name
500+
498501
def _set_cog(self, cog):
499502
self.cog = cog
500503

discord/ext/commands/cog.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from typing import Any, Callable, Generator, TYPE_CHECKING, List, TypeVar, Type, Union
3131

32-
from ...commands import ApplicationCommand
32+
from ...commands import ApplicationCommand, SlashCommandGroup
3333

3434
if TYPE_CHECKING:
3535
from .core import Command
@@ -59,14 +59,25 @@ def walk_commands(self) -> Generator[Command, None, None]:
5959
A command or group from the cog.
6060
"""
6161
from .core import GroupMixin
62+
print(self.__cog_commands__)
6263
for command in self.__cog_commands__:
63-
if isinstance(command, ApplicationCommand):
64-
yield command
65-
else:
64+
if not isinstance(command, ApplicationCommand):
6665
if command.parent is None:
6766
yield command
6867
if isinstance(command, GroupMixin):
6968
yield from command.walk_commands()
69+
elif isinstance(command, SlashCommandGroup):
70+
for subcommand in command.subcommands:
71+
print(subcommand)
72+
print(subcommand.parent)
73+
if subcommand.parent is not None and isinstance(subcommand, SlashCommandGroup):
74+
print("reach")
75+
for sub_subcommand in subcommand.subcommands:
76+
yield sub_subcommand
77+
else:
78+
yield subcommand
79+
else:
80+
yield command
7081

7182
def get_commands(self) -> List[Union[ApplicationCommand, Command]]:
7283
r"""

0 commit comments

Comments
 (0)