diff options
author | 2024-02-18 21:26:42 +0100 | |
---|---|---|
committer | 2024-03-21 14:29:02 +0100 | |
commit | e87a72191e30503dd059b984798a6eb380deaa4b (patch) | |
tree | 988bc7f9f37e3dac132fcba8d1a65cd42b531e3a | |
parent | implement the handler for the CommandOnCooldown exception (diff) |
implement the handler for the UserNotPlayingError exception
-rw-r--r-- | bot/command_error_handlers/user_not_playing.py | 23 | ||||
-rw-r--r-- | bot/exts/core/error_handler.py | 6 |
2 files changed, 24 insertions, 5 deletions
diff --git a/bot/command_error_handlers/user_not_playing.py b/bot/command_error_handlers/user_not_playing.py new file mode 100644 index 00000000..87542478 --- /dev/null +++ b/bot/command_error_handlers/user_not_playing.py @@ -0,0 +1,23 @@ +from typing import NoReturn + +from discord import Interaction +from discord.ext.commands import Context +from pydis_core.utils.error_handling.commands import AbstractCommandErrorHandler + +from bot.utils.exceptions import UserNotPlayingError + + +class UserNotPlayingErrorHandler(AbstractCommandErrorHandler): + """An handler for the UserNotPlayingError error.""" + + async def should_handle_error(self, error: Exception) -> bool: + """A predicate that determines whether the error should be handled or not.""" + return isinstance(error, UserNotPlayingError) + + async def handle_text_command_error(self, context: Context, error: Exception) -> NoReturn: + """Handle error raised in the context of text commands.""" + await context.send("Game not found.") + + async def handle_app_command_error(self, interaction: Interaction, error: Exception) -> NoReturn: + """Handle error raised in the context of app commands.""" + await interaction.response.send_message("Game not found.") diff --git a/bot/exts/core/error_handler.py b/bot/exts/core/error_handler.py index d1b098ba..17f9902c 100644 --- a/bot/exts/core/error_handler.py +++ b/bot/exts/core/error_handler.py @@ -8,7 +8,7 @@ from pydis_core.utils.logging import get_logger from bot.bot import Bot from bot.constants import Channels, Colours, ERROR_REPLIES, NEGATIVE_REPLIES from bot.utils.decorators import InChannelCheckFailure, InMonthCheckFailure -from bot.utils.exceptions import APIError, UserNotPlayingError +from bot.utils.exceptions import APIError log = get_logger(__name__) @@ -93,10 +93,6 @@ class CommandErrorHandler(commands.Cog): await ctx.send(embed=self.error_embed("You are not authorized to use this command.", NEGATIVE_REPLIES)) return - if isinstance(error, UserNotPlayingError): - await ctx.send("Game not found.") - return - if isinstance(error, APIError): await ctx.send( embed=self.error_embed( |