diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f0494f351..c0d6fa2960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ These changes are available on the `master` branch, but have not yet been releas ### Fixed +- Fix `ctx.command.qualified_name` returning only the parent `SlashCommandGroup` name + instead of the full subcommand path when accessed inside `cog_check`. + ([#3363](https://github.com/Pycord-Development/pycord/pull/3363)) - Fix `TypeError` when accessing `ApplicationCommand.guild_only` or `SlashCommandGroup.guild_only` when `contexts` is `None`. ([#3320](https://github.com/Pycord-Development/pycord/pull/3320)) diff --git a/discord/commands/core.py b/discord/commands/core.py index 1221a5abbc..237e23bc60 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -1527,6 +1527,32 @@ def inner(cls: type[SlashCommandGroup]) -> SlashCommandGroup: return inner + async def prepare(self, ctx: ApplicationContext) -> None: + # Resolve down to the actual leaf subcommand + leaf, data = self, ctx.interaction.data + while isinstance(leaf, SlashCommandGroup): + data = data["options"][0] + leaf = find(lambda x: x.name == data["name"], leaf.subcommands) + + ctx.command = leaf + + if not await self.can_run(ctx): + raise CheckFailure( + f"The check functions for the command {self.name} failed" + ) + + if self._max_concurrency is not None: + # For this application, context can be duck-typed as a Message + await self._max_concurrency.acquire(ctx) # type: ignore # ctx instead of non-existent message + + try: + self._prepare_cooldowns(ctx) + await self.call_before_hooks(ctx) + except: + if self._max_concurrency is not None: + await self._max_concurrency.release(ctx) # type: ignore # ctx instead of non-existent message + raise + async def _invoke(self, ctx: ApplicationContext) -> None: option = ctx.interaction.data["options"][0] resolved = ctx.interaction.data.get("resolved", None)