Skip to content

Commit

Permalink
Adding on_check_failure to View class (Pycord-Development#799)
Browse files Browse the repository at this point in the history
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
  • Loading branch information
3 people authored Aug 6, 2022
1 parent cffae79 commit 17af9d0
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 17af9d0

Please sign in to comment.