mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-18 23:15:48 +00:00
Ignore errors if it's already handled in app commands
This commit is contained in:
parent
f7c664e3e2
commit
84c38f1f22
@ -454,6 +454,23 @@ class Command(Generic[GroupT, P, T]):
|
||||
if parent.parent is not None:
|
||||
await parent.parent.on_error(interaction, self, error)
|
||||
|
||||
def _has_any_error_handlers(self) -> bool:
|
||||
if self.on_error is not None:
|
||||
return True
|
||||
|
||||
parent = self.parent
|
||||
if parent is not None:
|
||||
# Check if the on_error is overridden
|
||||
if parent.__class__.on_error is not Group.on_error:
|
||||
return True
|
||||
|
||||
if parent.parent is not None:
|
||||
parent_cls = parent.parent.__class__
|
||||
if parent_cls.on_error is not Group.on_error:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
async def _invoke_with_namespace(self, interaction: Interaction, namespace: Namespace) -> T:
|
||||
if not await self._check_can_run(interaction):
|
||||
raise CheckFailure(f'The check functions for command {self.name!r} failed.')
|
||||
@ -766,6 +783,9 @@ class ContextMenu:
|
||||
# Type checker does not understand negative narrowing cases like this function
|
||||
return await async_all(f(interaction) for f in predicates) # type: ignore
|
||||
|
||||
def _has_any_error_handlers(self) -> bool:
|
||||
return self.on_error is not None
|
||||
|
||||
async def _invoke(self, interaction: Interaction, arg: Any):
|
||||
try:
|
||||
if not await self._check_can_run(interaction):
|
||||
|
@ -677,7 +677,8 @@ class CommandTree(Generic[ClientT]):
|
||||
|
||||
A callback that is called when any command raises an :exc:`AppCommandError`.
|
||||
|
||||
The default implementation prints the traceback to stderr.
|
||||
The default implementation prints the traceback to stderr if the command does
|
||||
not have any error handlers attached to it.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
@ -690,6 +691,9 @@ class CommandTree(Generic[ClientT]):
|
||||
"""
|
||||
|
||||
if command is not None:
|
||||
if command._has_any_error_handlers():
|
||||
return
|
||||
|
||||
print(f'Ignoring exception in command {command.name!r}:', file=sys.stderr)
|
||||
else:
|
||||
print(f'Ignoring exception in command tree:', file=sys.stderr)
|
||||
|
Loading…
x
Reference in New Issue
Block a user