Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion discord/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ async def interaction_check(self, interaction: Interaction) -> bool:

The default implementation of this returns ``True``.

If this returns ``False``, :meth:`on_check_failure` is called.

.. note::

If an exception occurs within the body then the check
Expand Down Expand Up @@ -350,6 +352,18 @@ async def on_timeout(self) -> None:
self.disable_all_items()
await self._message.edit(view=self)

async def on_check_failure(self, interaction: Interaction) -> None:
"""|coro|
A callback that is called when a :meth:`View.interaction_check` returns ``False``.
This can be used to send a response when a check failure occurs.

Parameters
-----------
interaction: :class:`~discord.Interaction`
The interaction that occurred.
"""
pass

async def on_error(self, error: Exception, item: Item, interaction: Interaction) -> None:
"""|coro|

Expand Down Expand Up @@ -377,7 +391,7 @@ async def _scheduled_task(self, item: Item, interaction: Interaction):

allow = await self.interaction_check(interaction)
if not allow:
return
return await self.on_check_failure(interaction)

await item.callback(interaction)
except Exception as e:
Expand Down