1
0
mirror of https://github.com/Rapptz/discord.py.git synced 2025-05-10 15:59:50 +00:00

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

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

@ -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)