diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d407f3758..e90cbeff16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#3320](https://github.com/Pycord-Development/pycord/pull/3320)) - Fix `SyntaxWarning` about `return` in a `finally` block raised on Python 3.14+ ([#3332](https://github.com/Pycord-Development/pycord/pull/3334)) +- 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)) ### Deprecated 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)