Skip to content

Commit 6553f03

Browse files
committed
add the AbstractCommandErrorHandler interface
this represents an interface that all command handlers will need to implement in order to be able to use them in both app & text command errors
1 parent dc6dbbb commit 6553f03

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .abc import AbstractCommandErrorHandler
2+
3+
__all__ = ["AbstractCommandErrorHandler"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from abc import ABC, abstractmethod
2+
from typing import NoReturn
3+
4+
from discord import Interaction
5+
from discord.ext.commands import Context
6+
7+
8+
class AbstractCommandErrorHandler(ABC):
9+
"""An abstract command error handler."""
10+
11+
@abstractmethod
12+
async def should_handle_error(self, error: Exception) -> bool:
13+
"""A predicate that determines whether the error should be handled."""
14+
raise NotImplementedError
15+
16+
@abstractmethod
17+
async def handle_app_command_error(self, interaction: Interaction, error: Exception) -> NoReturn:
18+
"""Handle error raised in the context of app commands."""
19+
raise NotImplementedError
20+
21+
@abstractmethod
22+
async def handle_text_command_error(self, context: Context, error: Exception) -> NoReturn:
23+
"""Handle error raised in the context of text commands."""
24+
raise NotImplementedError

0 commit comments

Comments
 (0)