diff options
-rw-r--r-- | pydis_core/utils/error_handling/commands/__init__.py | 3 | ||||
-rw-r--r-- | pydis_core/utils/error_handling/commands/abc.py | 24 |
2 files changed, 27 insertions, 0 deletions
diff --git a/pydis_core/utils/error_handling/commands/__init__.py b/pydis_core/utils/error_handling/commands/__init__.py new file mode 100644 index 00000000..2b648c07 --- /dev/null +++ b/pydis_core/utils/error_handling/commands/__init__.py @@ -0,0 +1,3 @@ +from .abc import AbstractCommandErrorHandler + +__all__ = ["AbstractCommandErrorHandler"] diff --git a/pydis_core/utils/error_handling/commands/abc.py b/pydis_core/utils/error_handling/commands/abc.py new file mode 100644 index 00000000..f155b239 --- /dev/null +++ b/pydis_core/utils/error_handling/commands/abc.py @@ -0,0 +1,24 @@ +from abc import ABC, abstractmethod +from typing import NoReturn + +from discord import Interaction +from discord.ext.commands import Context + + +class AbstractCommandErrorHandler(ABC): + """An abstract command error handler.""" + + @abstractmethod + async def should_handle_error(self, error: Exception) -> bool: + """A predicate that determines whether the error should be handled.""" + raise NotImplementedError + + @abstractmethod + async def handle_app_command_error(self, interaction: Interaction, error: Exception) -> NoReturn: + """Handle error raised in the context of app commands.""" + raise NotImplementedError + + @abstractmethod + async def handle_text_command_error(self, context: Context, error: Exception) -> NoReturn: + """Handle error raised in the context of text commands.""" + raise NotImplementedError |