From 1232a1d2fd245822f9f5b4c56ddea2d7a98b2ef2 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 10 Apr 2022 19:05:32 -0400 Subject: [PATCH] [commands] Properly call after_hooks in hybrid commands --- discord/ext/commands/hybrid.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/discord/ext/commands/hybrid.py b/discord/ext/commands/hybrid.py index 6c7f26271..b6d694118 100644 --- a/discord/ext/commands/hybrid.py +++ b/discord/ext/commands/hybrid.py @@ -197,10 +197,9 @@ class HybridAppCommand(discord.app_commands.Command[CogT, P, T]): # If someone doesn't inherit this to replace it with their custom class # then this doesn't work. interaction._baton = ctx = await bot.get_context(interaction) - - exc: CommandError + command = self.wrapped try: - await self.wrapped.prepare(ctx) + await command.prepare(ctx) # This lies and just always passes a Context instead of an Interaction. return await self._do_call(ctx, ctx.kwargs) # type: ignore except app_commands.CommandSignatureMismatch: @@ -211,13 +210,18 @@ class HybridAppCommand(discord.app_commands.Command[CogT, P, T]): else: exc = HybridCommandError(e) exc.__cause__ = e + await command.dispatch_error(ctx, exc) except app_commands.AppCommandError as e: exc = HybridCommandError(e) exc.__cause__ = e + await command.dispatch_error(ctx, exc) except CommandError as e: - exc = e + await command.dispatch_error(ctx, e) + finally: + if command._max_concurrency is not None: + await command._max_concurrency.release(ctx.message) - await self.wrapped.dispatch_error(ctx, exc) + await command.call_after_hooks(ctx) class HybridCommand(Command[CogT, P, T]):