tickets_plus.ext.views
Generic discord.py views for tickets_plus.
Those are various buttons and select menus used throughout the bot. Note that these are not cogs, but rather discord.py views.
Typical usage example:
from tickets_plus.ext import views @bot.command() async def example(ctx): await ctx.send("Example", view=views.ExampleView()) ...
1"""Generic discord.py views for tickets_plus. 2 3Those are various buttons and select menus used throughout the bot. 4Note that these are not cogs, but rather discord.py views. 5 6Typical usage example: 7 ```py 8 from tickets_plus.ext import views 9 10 @bot.command() 11 async def example(ctx): 12 await ctx.send("Example", view=views.ExampleView()) 13 ... 14 ``` 15""" 16# License: EPL-2.0 17# SPDX-License-Identifier: EPL-2.0 18# Copyright (c) 2021-present The Tickets+ Contributors 19# This Source Code may also be made available under the following 20# Secondary Licenses when the conditions for such availability set forth 21# in the Eclipse Public License, v. 2.0 are satisfied: GPL-3.0-only OR 22# If later approved by the Initial Contributor, GPL-3.0-or-later. 23 24import discord 25 26 27class Confirm(discord.ui.View): 28 """A confirmation button set. 29 30 Allows the user to confirm or cancel an action. 31 32 Attributes: 33 value: Whether the user confirmed or not. 34 `None` if the user didn't confirm or cancel. 35 `bool` if the user confirmed or canceled. 36 """ 37 38 value: bool | None 39 40 def __init__(self): 41 """Initialises the view. 42 43 We prep the button and set return value to None. 44 """ 45 super().__init__() 46 self.value = None 47 48 @discord.ui.button(label="Confirm", style=discord.ButtonStyle.green) 49 async def confirm(self, interaction: discord.Interaction, button: discord.ui.Button): 50 """The 'confirm' button was pressed. 51 52 We set the return value to True, disable the button and stop the view. 53 54 Args: 55 interaction: The interaction that triggered the button. 56 button: The button that was pressed. 57 """ 58 await interaction.response.send_message("Confirmed", ephemeral=True) 59 self.value = True 60 button.disabled = True 61 self.stop() 62 63 @discord.ui.button(label="Cancel", style=discord.ButtonStyle.red) 64 async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button): 65 """The cancel button. 66 67 We set the return value to False, disable the button and stop the view. 68 69 Args: 70 interaction: The interaction that triggered the button. 71 button: The button that was pressed. 72 """ 73 await interaction.response.send_message("Cancelled", ephemeral=True) 74 self.value = False 75 button.disabled = True 76 self.stop()
class
Confirm(discord.ui.view.View):
28class Confirm(discord.ui.View): 29 """A confirmation button set. 30 31 Allows the user to confirm or cancel an action. 32 33 Attributes: 34 value: Whether the user confirmed or not. 35 `None` if the user didn't confirm or cancel. 36 `bool` if the user confirmed or canceled. 37 """ 38 39 value: bool | None 40 41 def __init__(self): 42 """Initialises the view. 43 44 We prep the button and set return value to None. 45 """ 46 super().__init__() 47 self.value = None 48 49 @discord.ui.button(label="Confirm", style=discord.ButtonStyle.green) 50 async def confirm(self, interaction: discord.Interaction, button: discord.ui.Button): 51 """The 'confirm' button was pressed. 52 53 We set the return value to True, disable the button and stop the view. 54 55 Args: 56 interaction: The interaction that triggered the button. 57 button: The button that was pressed. 58 """ 59 await interaction.response.send_message("Confirmed", ephemeral=True) 60 self.value = True 61 button.disabled = True 62 self.stop() 63 64 @discord.ui.button(label="Cancel", style=discord.ButtonStyle.red) 65 async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button): 66 """The cancel button. 67 68 We set the return value to False, disable the button and stop the view. 69 70 Args: 71 interaction: The interaction that triggered the button. 72 button: The button that was pressed. 73 """ 74 await interaction.response.send_message("Cancelled", ephemeral=True) 75 self.value = False 76 button.disabled = True 77 self.stop()
A confirmation button set.
Allows the user to confirm or cancel an action.
Attributes:
- value: Whether the user confirmed or not.
Noneif the user didn't confirm or cancel.boolif the user confirmed or canceled.
Confirm()
41 def __init__(self): 42 """Initialises the view. 43 44 We prep the button and set return value to None. 45 """ 46 super().__init__() 47 self.value = None
Initialises the view.
We prep the button and set return value to None.
async def
confirm( self, interaction: discord.interactions.Interaction, button: discord.ui.button.Button):
49 @discord.ui.button(label="Confirm", style=discord.ButtonStyle.green) 50 async def confirm(self, interaction: discord.Interaction, button: discord.ui.Button): 51 """The 'confirm' button was pressed. 52 53 We set the return value to True, disable the button and stop the view. 54 55 Args: 56 interaction: The interaction that triggered the button. 57 button: The button that was pressed. 58 """ 59 await interaction.response.send_message("Confirmed", ephemeral=True) 60 self.value = True 61 button.disabled = True 62 self.stop()
The 'confirm' button was pressed.
We set the return value to True, disable the button and stop the view.
Arguments:
- interaction: The interaction that triggered the button.
- button: The button that was pressed.
async def
cancel( self, interaction: discord.interactions.Interaction, button: discord.ui.button.Button):
64 @discord.ui.button(label="Cancel", style=discord.ButtonStyle.red) 65 async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button): 66 """The cancel button. 67 68 We set the return value to False, disable the button and stop the view. 69 70 Args: 71 interaction: The interaction that triggered the button. 72 button: The button that was pressed. 73 """ 74 await interaction.response.send_message("Cancelled", ephemeral=True) 75 self.value = False 76 button.disabled = True 77 self.stop()
The cancel button.
We set the return value to False, disable the button and stop the view.
Arguments:
- interaction: The interaction that triggered the button.
- button: The button that was pressed.