Skip to content

Commit

Permalink
[RedTree] add UserFeedbackCheckFailure for app_commands (#6397)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakub Kuczys <[email protected]>
  • Loading branch information
japandotorg and Jackenmen authored Jul 12, 2024
1 parent 2e40ec4 commit bf8c0d0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
"Category: Core - API - App Commands Package":
# Source
- redbot/core/app_commands/*
# Docs
- docs/framework_app_commands.rst
# Tests
- tests/core/test_app_commands.py
"Category: Core - API - Commands Package":
Expand Down
13 changes: 13 additions & 0 deletions docs/framework_app_commands.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. red app_commands module documentation
====================
App Commands Package
====================

This package acts almost identically to :doc:`discord.ext.app_commands <dpy:interactions/api>`; i.e.
all of the attributes from discord.py's are also in ours.
Some of these attributes, however, have been slightly modified, while others have been added to
extend functionalities used throughout the bot, as outlined below.

.. autoclass:: redbot.core.app_commands.UserFeedbackCheckFailure
:members:
3 changes: 3 additions & 0 deletions docs/framework_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ extend functionalities used throughout the bot, as outlined below.

.. autoclass:: redbot.core.commands.DMContext

.. autoclass:: redbot.core.commands.UserFeedbackCheckFailure
:members:

.. automodule:: redbot.core.commands.requires
:members: PrivilegeLevel, PermState, Requires

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Welcome to Red - Discord Bot's documentation!
framework_bot
framework_checks
framework_commands
framework_app_commands
framework_config
framework_datamanager
framework_events
Expand Down
4 changes: 4 additions & 0 deletions redbot/core/app_commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
)

from . import checks as checks
from .errors import (
UserFeedbackCheckFailure as UserFeedbackCheckFailure,
)

__all__ = (
"AllChannels",
Expand Down Expand Up @@ -131,4 +134,5 @@
"rename",
"user_install",
"checks",
"UserFeedbackCheckFailure",
)
10 changes: 10 additions & 0 deletions redbot/core/app_commands/errors.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions redbot/core/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Group,
NoPrivateMessage,
TransformerError,
UserFeedbackCheckFailure,
)
from .i18n import Translator
from .utils.chat_formatting import humanize_list, inline
Expand Down Expand Up @@ -327,6 +328,9 @@ async def on_error(
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.")
Expand Down

0 comments on commit bf8c0d0

Please sign in to comment.