Skip to content

Buttons

ballsdex.core.utils.buttons

ConfirmChoiceView

ConfirmChoiceView(interaction: Interaction[BallsDexBot], user: User | None = None, accept_message: str = 'Confirmed', cancel_message: str = 'Cancelled')

Bases: View

An utility to prompt the user for confirmation.

Parameters:

  • interaction (Interaction[BallsDexBot]) –

    The original interaction.

  • user (User | None, default: None ) –

    The user you're interacting with. If None, then interaction.user is used.

  • accept_message (str, default: 'Confirmed' ) –

    The message appended to the message's content if the prompt is accepted.

  • cancel_message (str, default: 'Cancelled' ) –

    The message appended to the message's content if the prompt is refused.

Attributes:

  • value (bool | None) –

    The user's choice. None if the interaction timed out or didn't finish. Call wait() first.

Example
view = ConfirmChoiceView(interaction)
await interaction.response.send_message("Are you sure?", view=view)
await view.wait()
if view.value is True:
    # user accepted
elif view.value is False:
    # user denied
elif view.value is None:
    # timed out
Source code in ballsdex/core/utils/buttons.py
def __init__(
    self,
    interaction: discord.Interaction["BallsDexBot"],
    user: Optional[discord.User] = None,
    accept_message: str = "Confirmed",
    cancel_message: str = "Cancelled",
):
    super().__init__(timeout=90)
    self.value = None
    self.interaction = interaction
    self.user = user or interaction.user
    self.interaction_response: discord.Interaction["BallsDexBot"]
    self.accept_message = accept_message
    self.cancel_message = cancel_message