From 5bc085ebabc979da323109167e8a147c082a9acb Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 15 Mar 2022 03:15:07 -0400 Subject: [PATCH] Properly set root parent before copying a command's binding --- discord/app_commands/commands.py | 2 +- discord/ext/commands/cog.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index d1db76a7e..83a703b8c 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -757,8 +757,8 @@ class Group: self._children: Dict[str, Union[Command, Group]] = {} for child in self.__discord_app_commands_group_children__: - child = child._copy_with_binding(self) if not cls.__discord_app_commands_skip_init_binding__ else child child.parent = self + child = child._copy_with_binding(self) if not cls.__discord_app_commands_skip_init_binding__ else child self._children[child.name] = child if child._attr and not cls.__discord_app_commands_skip_init_binding__: setattr(self, child._attr, child) diff --git a/discord/ext/commands/cog.py b/discord/ext/commands/cog.py index 59eb54c4e..39a32e3cd 100644 --- a/discord/ext/commands/cog.py +++ b/discord/ext/commands/cog.py @@ -249,12 +249,12 @@ class Cog(metaclass=CogMeta): # Register the application commands children: List[Union[app_commands.Group, app_commands.Command[Self, ..., Any]]] = [] for command in cls.__cog_app_commands__: - copy = command._copy_with_binding(self) - if cls.__cog_is_app_commands_group__: # Type checker doesn't understand this type of narrowing. # Not even with TypeGuard somehow. - copy.parent = self # type: ignore + command.parent = self # type: ignore + + copy = command._copy_with_binding(self) children.append(copy) if command._attr: