Untitled
unknown
plain_text
2 years ago
3.0 kB
6
Indexable
class ButtonView(View):
def __init__(self, parent_view, embed):
super().__init__()
self.parent_view = parent_view
self.embed = embed
@discord.ui.button(label="Title", style=discord.ButtonStyle.secondary())
async def title_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message(TitleModal())
@discord.ui.button(label="Description", style=discord.ButtonStyle.secondary())
async def description_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message(DescriptionModal())
@discord.ui.button(label="Date", style=discord.ButtonStyle.secondary())
async def date_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message(DateModal())
@discord.ui.button(label="Confirm", style=discord.ButtonStyle.success())
async def confirm_button(self, interaction: discord.Interaction):
await interaction.response.send_message("Confirmed!", ephemeral=True)
class TitleModal(discord.ui.Modal):
def __init__(self, parent_view):
self.parent_view = parent_view
super().__init__(title="Enter a Title")
self.title_input = discord.ui.TextInput(label="Title", placeholder="Enter title here...", required=True, max_length=50)
self.add_item(self.title_input)
async def on_submit(self, interaction: discord.Interaction):
title = self.title_input.value
self.parent_view.update_embed(title=title)
await interaction.response.edit_message(embed=self.parent_view.embed, view=self.parent_view)
class DescriptionModal(discord.ui.Modal):
def __init__(self, parent_view):
self.parent_view = parent_view
super().__init__(description="Enter a Description")
self.description_input = discord.ui.TextInput(label="Description", placeholder="Enter description here...", required=True, max_length=500)
self.add_item(self.description_input)
async def on_submit(self, interaction: discord.Interaction):
description = self.description_input.value
self.parent_view.update_embed(description=description)
await interaction.response.edit_message(embed=self.parent_view.embed, view=self.parent_view)
class DateModal(discord.ui.Modal):
def __init__(self, parent_view):
self.parent_view = parent_view
super().__init__(date="Enter a Date")
self.date_input = discord.ui.TextInput(label="Date", placeholder="Enter date here...", required=True, max_length=8)
self.add_item(self.date_input)
async def on_submit(self, interaction: discord.Interaction):
date = self.date_input.value
self.parent_view.update_embed(date=date)
await interaction.response.edit_message(embed=self.parent_view.embed, view=self.parent_view)Editor is loading...
Leave a Comment