From 52fcaed79bd21b3a6ef712f6335a2d9d695ecf29 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 11 Apr 2022 00:38:38 -0400 Subject: [PATCH] [commands] Reassign app_command attribute on copy Prior to this change it would re-create the HybridAppCommand on copy which had the consequence of clearing parameter related changes. --- discord/ext/commands/hybrid.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/discord/ext/commands/hybrid.py b/discord/ext/commands/hybrid.py index b6d694118..33b90ed10 100644 --- a/discord/ext/commands/hybrid.py +++ b/discord/ext/commands/hybrid.py @@ -136,6 +136,12 @@ class HybridAppCommand(discord.app_commands.Command[CogT, P, T]): copy.wrapped = self.wrapped return copy + def copy(self) -> Self: + bindings = { + self.binding: self.binding, + } + return self._copy_with(parent=self.parent, binding=self.binding, bindings=bindings) + async def _check_can_run(self, interaction: discord.Interaction) -> bool: # Hybrid checks must run like so: # - Bot global check once @@ -271,6 +277,10 @@ class HybridCommand(Command[CogT, P, T]): else: ctx.kwargs = await self.app_command._transform_arguments(interaction, interaction.namespace) + def _ensure_assignment_on_copy(self, other: Self) -> Self: + copy = super()._ensure_assignment_on_copy(other) + copy.app_command = self.app_command.copy() + return copy class HybridGroup(Group[CogT, P, T]): r"""A class that is both an application command group and a regular text group.