Properly set root parent before copying a command's binding

This commit is contained in:
Rapptz 2022-03-15 03:15:07 -04:00
parent ca4db68686
commit 5bc085ebab
2 changed files with 4 additions and 4 deletions

View File

@ -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)

View File

@ -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: