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

Fix #8276
This commit is contained in:
Rapptz 2022-07-29 21:39:23 -04:00
parent dc8cbc073e
commit c43d302a28

View File

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