Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
3.5 kB
1
Indexable
Never
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):
        super().__init__(title="Enter a Title")
        self.title_input = discord.ui.TextInput(label="Title", placeholder="Enter your title here...", required=True, max_length=50)
        self.add_item(self.title_input)
        
    @discord.ui.button(label="Description", style=discord.ButtonStyle.secondary())
    async def description_button(self, interaction: discord.Interaction, button: discord.ui.Button):
        super().__init__(title="Enter a Description")
        self.description_input = discord.ui.TextInput(label="Description", placeholder="Enter your description here...", required=True, max_length=500)
        self.add_item(self.description_input)
        
    @discord.ui.button(label="Date", style=discord.ButtonStyle.secondary())
    async def date_button(self, interaction: discord.Interaction, button: discord.ui.Button):
        super().__init__(title="Enter a Date")
        self.date_input = discord.ui.TextInput(label="Date", placeholder="Enter the current date...", required=True, max_length=8)
        self.add_item(self.date_input)
        
    
    # Handle form submission
    async def on_submit(self, interaction: discord.Interaction):
        # Update the embed with the entered title
        title = self.title_input.value
        description = self.description_input.value
        date = self.date_input.value
        self.parent_view.update_embed(title=title)
        self.parent_view.update_embed(description=description)
        self.parent_view.update_embed(date=date)
        await interaction.response.edit_message(embed=self.parent_view.embed, view=self.parent_view)
     
    @discord.ui.button(label="Confirm", style=discord.ButtonStyle.success())
    async def callback(self, interaction: discord.Interaction):
        await interaction.response.send_message("Confirmed!", ephemeral=True)

     
     
class ButtonModal(discord.ui.Modal):
    def __init__(self, parent_view, embed):
        self.parent_view = parent_view
        self.embed = embed
        super().__init__(title="Enter a Title")
        super().__init__(description="Enter a Description")
        super().__init__(date="Enter a Date")
        self.title_input = discord.ui.TextInput(label="Title", placeholder="Enter the title here...", required=True, max_length=50)
        self.description_input = discord.ui.TextInput(label="Description", placeholder="Enter the description here...", required=True, max_length=500)
        self.date_input = discord.ui.TextInput(label="Date", placeholder="Enter the current date here...", required=True, max_length=8)
        self.add_item(self.title_input)
        self.add_item(self.description_input)
        self.add_item(self.date_input)
    
    async def on_submit(self, interaction: discord.Interaction):
        title = self.title_input.value
        description = self.description_input.value
        date = self.date_input.value
        self.parent_view.update_embed(title=title, description=description, date=date)
        await interaction.response.edit_message(embed=self.parent_view.embed, view=self.parent_view)
Leave a Comment