mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-21 00:07:51 +00:00
[commands] Fix app command children not being copied in HybridGroup
This degenerate case is only triggered inside cogs when using the app_command property to define commands, such as this: class X(commands.Cog): @commands.hybrid_group() async def foo(self, ctx): ... @foo.app_command.command() async def bar(self, interaction): ...
This commit is contained in:
parent
85ad33eb35
commit
bd3ce597e1
@ -289,17 +289,19 @@ class Cog(metaclass=CogMeta):
|
||||
# Update our parent's reference to our self
|
||||
parent.remove_command(command.name) # type: ignore
|
||||
parent.add_command(command) # type: ignore
|
||||
elif self.__cog_app_commands_group__:
|
||||
if hasattr(command, '__commands_is_hybrid__') and command.parent is None:
|
||||
parent = self.__cog_app_commands_group__
|
||||
app_command: Optional[Union[app_commands.Group, app_commands.Command[Self, ..., Any]]] = getattr(
|
||||
command, 'app_command', None
|
||||
)
|
||||
if app_command:
|
||||
app_command = app_command._copy_with(parent=parent, binding=self)
|
||||
|
||||
if hasattr(command, '__commands_is_hybrid__') and parent is None:
|
||||
app_command: Optional[Union[app_commands.Group, app_commands.Command[Self, ..., Any]]] = getattr(
|
||||
command, 'app_command', None
|
||||
)
|
||||
if app_command:
|
||||
group_parent = self.__cog_app_commands_group__
|
||||
app_command = app_command._copy_with(parent=group_parent, binding=self)
|
||||
# The type checker does not see the app_command attribute even though it exists
|
||||
command.app_command = app_command # type: ignore
|
||||
|
||||
if self.__cog_app_commands_group__:
|
||||
children.append(app_command)
|
||||
# The type checker does not see the app_command attribute even though it exists
|
||||
command.app_command = app_command # type: ignore
|
||||
|
||||
for command in cls.__cog_app_commands__:
|
||||
copy = command._copy_with(parent=self.__cog_app_commands_group__, binding=self)
|
||||
|
@ -565,6 +565,19 @@ class HybridGroup(Group[CogT, P, T]):
|
||||
copy.fallback = self.fallback
|
||||
return copy
|
||||
|
||||
def _update_copy(self, kwargs: Dict[str, Any]) -> Self:
|
||||
copy = super()._update_copy(kwargs)
|
||||
# This is only really called inside CogMeta
|
||||
# I want to ensure that the children of the app command are copied
|
||||
# For example, if someone defines an app command using the app_command property
|
||||
# while inside the cog. This copy is not propagated in normal means.
|
||||
# For some reason doing this copy above will lead to duplicates.
|
||||
if copy.app_command and self.app_command:
|
||||
# This is a very lazy copy because the CogMeta will properly copy it
|
||||
# with bindings and all later
|
||||
copy.app_command._children = self.app_command._children.copy()
|
||||
return copy
|
||||
|
||||
def autocomplete(
|
||||
self, name: str
|
||||
) -> Callable[[AutocompleteCallback[CogT, ChoiceT]], AutocompleteCallback[CogT, ChoiceT]]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user