diff options
-rw-r--r-- | bot/command_error_handlers/__init__.py | 2 | ||||
-rw-r--r-- | bot/command_error_handlers/disabled_command.py | 27 | ||||
-rw-r--r-- | bot/exts/core/error_handler.py | 6 |
3 files changed, 30 insertions, 5 deletions
diff --git a/bot/command_error_handlers/__init__.py b/bot/command_error_handlers/__init__.py index cd6be708..a9406380 100644 --- a/bot/command_error_handlers/__init__.py +++ b/bot/command_error_handlers/__init__.py @@ -8,6 +8,7 @@ from .check_failure import CheckFailureErrorHandler from .command_not_found import CommandNotFoundErrorHandler from .command_on_cooldown import CommandOnCooldownErrorHandler from .default import DefaultCommandErrorHandler +from .disabled_command import DisabledCommandErrorHandler from .moved_command import MovedCommandErrorHandler from .user_input_error import UserInputErrorHandler from .user_not_playing import UserNotPlayingErrorHandler @@ -25,4 +26,5 @@ def bootstrap_command_error_manager(bot: Bot) -> CommandErrorManager: manager.register_handler(UserNotPlayingErrorHandler()) manager.register_handler(BadArgumentErrorHandler()) manager.register_handler(CheckFailureErrorHandler()) + manager.register_handler(DisabledCommandErrorHandler()) return manager diff --git a/bot/command_error_handlers/disabled_command.py b/bot/command_error_handlers/disabled_command.py new file mode 100644 index 00000000..8b277198 --- /dev/null +++ b/bot/command_error_handlers/disabled_command.py @@ -0,0 +1,27 @@ +from typing import NoReturn + +from discord import Interaction +from discord.ext.commands import Context, DisabledCommand +from pydis_core.utils.error_handling.commands import AbstractCommandErrorHandler + +from bot.constants import NEGATIVE_REPLIES + +from ._utils import create_error_embed + + +class DisabledCommandErrorHandler(AbstractCommandErrorHandler): + """An handler for the DisabledCommand 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, DisabledCommand) + + async def handle_text_command_error(self, context: Context, error: Exception) -> NoReturn: + """Handle error raised in the context of text commands.""" + await context.send(embed=create_error_embed("This command has been disabled.", NEGATIVE_REPLIES)) + + 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( + embed=create_error_embed("This command has been disabled.", NEGATIVE_REPLIES) + ) diff --git a/bot/exts/core/error_handler.py b/bot/exts/core/error_handler.py index d8e2380e..ef694f0c 100644 --- a/bot/exts/core/error_handler.py +++ b/bot/exts/core/error_handler.py @@ -6,7 +6,7 @@ from discord.ext import commands from pydis_core.utils.logging import get_logger from bot.bot import Bot -from bot.constants import Colours, ERROR_REPLIES, NEGATIVE_REPLIES +from bot.constants import Colours, ERROR_REPLIES log = get_logger(__name__) @@ -55,10 +55,6 @@ class CommandErrorHandler(commands.Cog): f"Channel: {ctx.channel}" ) - if isinstance(error, commands.DisabledCommand): - await ctx.send(embed=self.error_embed("This command has been disabled.", NEGATIVE_REPLIES)) - return - await self.bot.command_error_manager.handle_error(error, ctx) |