Skip to content

Commit 5066886

Browse files
authored
Merge pull request #967 from Middledot/master
fix cog.walk_commands() and SlashCommandGroup
2 parents e133f84 + 6cf80ab commit 5066886

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

discord/cog.py

Lines changed: 3 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,8 @@ 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+
yield from command.walk_commands()
280280

281281
def get_listeners(self) -> List[Tuple[str, Callable[..., Any]]]:
282282
"""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: 6 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
@@ -60,13 +60,15 @@ def walk_commands(self) -> Generator[Command, None, None]:
6060
"""
6161
from .core import GroupMixin
6262
for command in self.__cog_commands__:
63-
if isinstance(command, ApplicationCommand):
64-
yield command
65-
else:
63+
if not isinstance(command, ApplicationCommand):
6664
if command.parent is None:
6765
yield command
6866
if isinstance(command, GroupMixin):
6967
yield from command.walk_commands()
68+
elif isinstance(command, SlashCommandGroup):
69+
yield from command.walk_commands()
70+
else:
71+
yield command
7072

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

0 commit comments

Comments
 (0)