aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar shtlrs <[email protected]>2024-02-18 21:26:42 +0100
committerGravatar shtlrs <[email protected]>2024-03-20 19:15:04 +0100
commit86beb4c63c90d1910ea963e9a1d2435e048c940d (patch)
tree4dbdd27fbd4edf9b1e746d30bd81a526e318b3a1
parentimplement the handler for the CommandOnCooldown exception (diff)
implement the handler for the UserNotPlayingError exception
-rw-r--r--bot/command_error_handlers/user_not_playing.py21
-rw-r--r--bot/exts/core/error_handler.py6
2 files changed, 22 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..b3238a79
--- /dev/null
+++ b/bot/command_error_handlers/user_not_playing.py
@@ -0,0 +1,21 @@
+from typing import NoReturn
+
+from discord import Interaction
+from discord.ext.commands import CommandOnCooldown, Context
+from pydis_core.utils.error_handling.commands import AbstractCommandErrorHandler
+
+
+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, CommandOnCooldown)
+
+ 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(