Browse Source

[commands] Only call hybrid after_invoke hooks if the command is called

Fix #8276
pull/8280/head
Rapptz 3 years ago
parent
commit
c43d302a28
  1. 5
      discord/ext/commands/hybrid.py

5
discord/ext/commands/hybrid.py

@ -419,10 +419,12 @@ class HybridAppCommand(discord.app_commands.Command[CogT, P, T]):
command = self.wrapped
bot.dispatch('command', ctx)
value = None
callback_completed = False
try:
await command.prepare(ctx)
# This lies and just always passes a Context instead of an Interaction.
value = await self._do_call(ctx, ctx.kwargs) # type: ignore
callback_completed = True
except app_commands.CommandSignatureMismatch:
raise
except (app_commands.TransformerError, app_commands.CommandInvokeError) as e:
@ -442,7 +444,8 @@ class HybridAppCommand(discord.app_commands.Command[CogT, P, T]):
if command._max_concurrency is not None:
await command._max_concurrency.release(ctx.message)
await command.call_after_hooks(ctx)
if callback_completed:
await command.call_after_hooks(ctx)
if not ctx.command_failed:
bot.dispatch('command_completion', ctx)

Loading…
Cancel
Save