[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:
Rapptz
2022-05-06 09:00:03 -04:00
parent 85ad33eb35
commit bd3ce597e1
2 changed files with 25 additions and 10 deletions

View File

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