[RedTree] add UserFeedbackCheckFailure for app_commands (#6397)

Co-authored-by: Jakub Kuczys <me@jacken.men>
This commit is contained in:
Lemon Rose
2024-07-12 23:00:22 +05:30
committed by GitHub
parent 2e40ec4a1a
commit bf8c0d03b5
7 changed files with 37 additions and 0 deletions

View File

@@ -69,6 +69,9 @@ from discord.app_commands import (
)
from . import checks as checks
from .errors import (
UserFeedbackCheckFailure as UserFeedbackCheckFailure,
)
__all__ = (
"AllChannels",
@@ -131,4 +134,5 @@ __all__ = (
"rename",
"user_install",
"checks",
"UserFeedbackCheckFailure",
)

View File

@@ -0,0 +1,10 @@
"""Errors module for the app_commands package."""
from discord import app_commands
class UserFeedbackCheckFailure(app_commands.CheckFailure):
"""A version of CheckFailure responding with a custom error message."""
def __init__(self, message=None, *args):
self.message = message
super().__init__(message, *args)

View File

@@ -17,6 +17,7 @@ from .app_commands import (
Group,
NoPrivateMessage,
TransformerError,
UserFeedbackCheckFailure,
)
from .i18n import Translator
from .utils.chat_formatting import humanize_list, inline
@@ -327,6 +328,9 @@ class RedTree(CommandTree):
relative_time=relative_time
)
await self._send_from_interaction(interaction, msg, delete_after=error.retry_after)
elif isinstance(error, UserFeedbackCheckFailure):
if error.message:
await self._send_from_interaction(interaction, error.message)
elif isinstance(error, CheckFailure):
await self._send_from_interaction(
interaction, _("You are not permitted to use this command.")