mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +00:00
Fix detection of overriden Group.on_error and ensure they're copied
This commit is contained in:
parent
03d7a9a719
commit
6bec7e9d97
@ -461,6 +461,11 @@ def _get_context_menu_parameter(func: ContextMenuCallback) -> Tuple[str, Any, Ap
|
|||||||
return (parameter.name, resolved, type)
|
return (parameter.name, resolved, type)
|
||||||
|
|
||||||
|
|
||||||
|
def mark_overrideable(func: F) -> F:
|
||||||
|
func.__discord_app_commands_base_function__ = None
|
||||||
|
return func
|
||||||
|
|
||||||
|
|
||||||
class Parameter:
|
class Parameter:
|
||||||
"""A class that contains the parameter information of a :class:`Command` callback.
|
"""A class that contains the parameter information of a :class:`Command` callback.
|
||||||
|
|
||||||
@ -818,12 +823,11 @@ class Command(Generic[GroupT, P, T]):
|
|||||||
parent = self.parent
|
parent = self.parent
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
# Check if the on_error is overridden
|
# Check if the on_error is overridden
|
||||||
if parent.__class__.on_error is not Group.on_error:
|
if not hasattr(parent.on_error, '__discord_app_commands_base_function__'):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if parent.parent is not None:
|
if parent.parent is not None:
|
||||||
parent_cls = parent.parent.__class__
|
if not hasattr(parent.parent.on_error, '__discord_app_commands_base_function__'):
|
||||||
if parent_cls.on_error is not Group.on_error:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@ -1648,6 +1652,9 @@ class Group:
|
|||||||
copy._children = {}
|
copy._children = {}
|
||||||
copy.extras = self.extras
|
copy.extras = self.extras
|
||||||
|
|
||||||
|
if not hasattr(self.on_error, '__discord_app_commands_base_function__'):
|
||||||
|
copy.on_error = self.on_error
|
||||||
|
|
||||||
bindings[self] = copy
|
bindings[self] = copy
|
||||||
|
|
||||||
for child in self._children.values():
|
for child in self._children.values():
|
||||||
@ -1747,6 +1754,7 @@ class Group:
|
|||||||
if isinstance(command, Group):
|
if isinstance(command, Group):
|
||||||
yield from command.walk_commands()
|
yield from command.walk_commands()
|
||||||
|
|
||||||
|
@mark_overrideable
|
||||||
async def on_error(self, interaction: Interaction, error: AppCommandError, /) -> None:
|
async def on_error(self, interaction: Interaction, error: AppCommandError, /) -> None:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user