Browse Source

Fix cog_app_command_error for group edge case

pull/8279/head
StockerMC 3 years ago
committed by Danny
parent
commit
1fbcfbd1fb
  1. 9
      discord/app_commands/commands.py
  2. 9
      discord/ext/commands/cog.py

9
discord/app_commands/commands.py

@ -613,7 +613,7 @@ class Command(Generic[GroupT, P, T]):
if parent.parent is not None:
await parent.parent.on_error(interaction, error)
binding_error_handler = getattr(self.binding, '__app_commands_error_handler__', None)
binding_error_handler = getattr(self.binding, '__discord_app_commands_error_handler__', None)
if binding_error_handler is not None:
await binding_error_handler(interaction, error)
@ -1143,6 +1143,9 @@ class Group:
__discord_app_commands_guild_only__: bool = MISSING
__discord_app_commands_default_permissions__: Optional[Permissions] = MISSING
__discord_app_commands_has_module__: bool = False
__discord_app_commands_error_handler__: Optional[
Callable[[Interaction, AppCommandError], Coroutine[Any, Any, None]]
] = None
def __init_subclass__(
cls,
@ -1269,10 +1272,6 @@ class Group:
raise ValueError('groups can only be nested at most one level')
parent.add_command(self)
self.__app_commands_error_handler__: Optional[
Callable[[Interaction, AppCommandError], Coroutine[Any, Any, None]]
] = None
def __set_name__(self, owner: Type[Any], name: str) -> None:
self._attr = name
self.module = owner.__module__

9
discord/ext/commands/cog.py

@ -268,7 +268,7 @@ class Cog(metaclass=CogMeta):
__cog_listeners__: List[Tuple[str, str]]
__cog_is_app_commands_group__: ClassVar[bool] = False
__cog_app_commands_group__: Optional[app_commands.Group]
__app_commands_error_handler__: Optional[
__discord_app_commands_error_handler__: Optional[
Callable[[discord.Interaction, app_commands.AppCommandError], Coroutine[Any, Any, None]]
]
@ -333,7 +333,7 @@ class Cog(metaclass=CogMeta):
else:
error_handler = None
self.__app_commands_error_handler__ = error_handler
self.__discord_app_commands_error_handler__ = error_handler
for command in cls.__cog_app_commands__:
copy = command._copy_with(parent=self.__cog_app_commands_group__, binding=self)
@ -343,7 +343,10 @@ class Cog(metaclass=CogMeta):
setattr(self, copy._attr, copy)
if isinstance(copy, app_commands.Group):
copy.__app_commands_error_handler__ = error_handler
copy.__discord_app_commands_error_handler__ = error_handler
for command in copy._children.values():
if isinstance(command, app_commands.Group):
command.__discord_app_commands_error_handler__ = error_handler
children.append(copy)

Loading…
Cancel
Save