Question : discordpy modal
Answered by : jittery-jay-8a0spdv7lmkk
import discord
from discord import TextInput
class Modal(discord.ui.Modal, title="Modal title"): def __init__(self): super().__init__() self.add_item(TextInput(label="Title1", placeholder="placeholder", default="default value")) self.add_item(TextInput(label="Hi", placeholder="write your name", style=discord.TextStyle.short)) async def on_submit(self, interaction: discord.Interaction) -> None: await interaction.response.send_message(f"Hello {self.children[1]} !") async def on_error(self, interaction: discord.Interaction, error: Exception) -> None: await interaction.response.send_message(f"Oops, an error has occured ... ({error.with_traceback})")
# ...............
@app_commands.command(name="hello", description="Hello from the bot !")
async def hello(self, interaction: discord.Interaction): await interaction.response.send_modal(Modal())
Source : | Last Update : Sun, 14 Aug 22