Skip to content

fix(commands): run parent command's after_invoke before invoking children - #1584

Open
shiftinv wants to merge 2 commits into
masterfrom
fix/slash-after-invoke
Open

fix(commands): run parent command's after_invoke before invoking children#1584
shiftinv wants to merge 2 commits into
masterfrom
fix/slash-after-invoke

Conversation

@shiftinv

Copy link
Copy Markdown
Member

Summary

Fixes #893, supersedes #1192.

The issue in #893 is actually a side-effect of another bug - a parent slash command's after_invoke currently runs after the hooks and invokes of the group/sub command. This is unlike prefix commands, which are all self-contained before -> invoke -> after sets for each group/command in the chain.
Running the parent slash command's after_invoke late then also meant that Interaction.application_command was set to the subcommand, as its .prepare() had already run.

I've marked this as a breaking change just to be on the safe side, though it shouldn't have a significant impact.

To maybe illustrate ths a bit better, consider a root command, with a group sub command group, which has a sub sub command -

# before
root.before_invoke()
root.invoke()
  group.before_invoke()
  group.invoke()
  group.after_invoke()
    sub.before_invoke()
    sub.invoke()
    sub.after_invoke()
root.after_invoke()

# after (also matching prefix cmd behavior)
root.before_invoke()
root.invoke()
root.after_invoke()
  group.before_invoke()
  group.invoke()
  group.after_invoke()
    sub.before_invoke()
    sub.invoke()
    sub.after_invoke()

Checklist

  • If code changes were made, then they have been tested
    • I have updated the documentation to reflect the changes
    • I have formatted the code properly by running uv run nox -s lint
    • I have type-checked the code by running uv run nox -s pyright
  • This PR fixes an issue
  • This PR adds something new (e.g. new method or parameters)
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@shiftinv shiftinv added this to the disnake v2.13 milestone Jul 28, 2026
@shiftinv shiftinv added breaking change Includes breaking changes to code/packaging t: bugfix labels Jul 28, 2026
@shiftinv shiftinv added this to disnake Jul 28, 2026
@github-project-automation github-project-automation Bot moved this to Todo in disnake Jul 28, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 disnake | 🛠️ Build #33802769 | 📁 Comparing 1a2ae11 against latest (c85e0b4)

  🔍 Preview build  

48 files changed · ± 48 modified

± Modified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Includes breaking changes to code/packaging t: bugfix

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

ApplicationCommandInteraction.slash_command of parent command is overwrited by children command invokations

1 participant