I want to create a modal like in the picture when the button is pressed. How can I make this model with Discord.py or nextcord?

enter image description here

2

Best Answer


You can find examples for modals in Nextcord here:

https://github.com/nextcord/nextcord/blob/master/examples/modals/

class Pet(nextcord.ui.Modal):def __init__(self):super().__init__("Your pet") # Modal title# Create a text input and add it to the modalself.name = nextcord.ui.TextInput(label="Your pet's name",min_length=2,max_length=50,)self.add_item(self.name)# Create a long text input and add it to the modalself.description = nextcord.ui.TextInput(label="Description",style=nextcord.TextInputStyle.paragraph,placeholder="Information that can help us recognise your pet",required=False,max_length=1800,)self.add_item(self.description)async def callback(self, interaction: nextcord.Interaction) -> None:"""This is the function that gets called when the submit button is pressed"""response = f"{interaction.user.mention}'s favourite pet's name is {self.name.value}."if self.description.value != "":response += f"\nTheir pet can be recognized by this information:\n{self.description.value}"await interaction.send(response)@bot.slash_command(name="pet",description="Describe your favourite pet",guild_ids=[TESTING_GUILD_ID],)async def send(interaction: nextcord.Interaction):# sending the modal on an interaction (can be slash, buttons, or select menus)modal = Pet()await interaction.response.send_modal(modal)
class Modal(ui.Modal, title="test title"):firstfield = ui.TextInput(label="firstfield",placeholder="write here", style=discord.TextStyle.short)secondfield = ui.TextInput(label="secondfield",placeholder="write here", style=discord.TextStyle.short)thirdfield = ui.TextInput(label="thirdfield:",placeholder="write here", style=discord.TextStyle.short)first_big_field = ui.TextInput(label="first_big_field:",placeholder="write here", style=discord.TextStyle.long)second_big_field = ui.TextInput(label="second_big_field:",placeholder="write here", style=discord.TextStyle.long)

Then u can call Modal() where u want