[commands] Add cog-level app command error special method

This commit is contained in:
Stocker
2022-07-17 23:45:19 -04:00
committed by GitHub
parent 2067819b75
commit 0546343bcb
3 changed files with 57 additions and 5 deletions

View File

@@ -598,7 +598,7 @@ class Command(Generic[GroupT, P, T]):
return base
async def _invoke_error_handler(self, interaction: Interaction, error: AppCommandError) -> None:
async def _invoke_error_handlers(self, interaction: Interaction, error: AppCommandError) -> None:
# These type ignores are because the type checker can't narrow this type properly.
if self.on_error is not None:
if self.binding is not None:
@@ -613,6 +613,10 @@ class Command(Generic[GroupT, P, T]):
if parent.parent is not None:
await parent.parent.on_error(interaction, error)
cog_error = getattr(self.binding, '__app_commands_error_handler__', None)
if cog_error is not None:
await cog_error(interaction, error)
def _has_any_error_handlers(self) -> bool:
if self.on_error is not None:
return True