CreateModal
CreateModal creates a modal popup form that Discord displays to a user. Modals can contain 1–5 CreateActionRow<CreateTextInput> rows.
Import
Section titled “Import”import { CreateModal, CreateActionRow, CreateTextInput, TextInputType } from "lunibee";import { CreateModal, CreateActionRow, CreateTextInput, TextInputType } from "lunibee";Methods
Section titled “Methods”setCustomId(id)
Section titled “setCustomId(id)”Sets the custom ID used to identify this modal when submitted (max 100 characters).
modal.setCustomId("ticket_modal");modal.setCustomId("ticket_modal");setTitle(title)
Section titled “setTitle(title)”Sets the modal window title (max 45 characters).
modal.setTitle("Open a Support Ticket");modal.setTitle("Open a Support Ticket");addComponents(...rows)
Section titled “addComponents(...rows)”Adds CreateActionRow<CreateTextInput> rows to the modal (1–5). Throws a TypeError when called with none and a RangeError past five rows.
modal.addComponents( new CreateActionRow<CreateTextInput>().addComponents( new CreateTextInput() .setCustomId("subject") .setLabel("Subject") .setStyle(TextInputType.Short) .setRequired(true), ),);modal.addComponents( new CreateActionRow().addComponents( new CreateTextInput() .setCustomId("subject") .setLabel("Subject") .setStyle(TextInputType.Short) .setRequired(true), ),);toJSON()
Section titled “toJSON()”Serializes to a raw Discord API-compatible modal object. Throws when the custom ID or title is missing, or when the modal has no components.
CreateTextInput
Section titled “CreateTextInput”Methods
Section titled “Methods”| Method | Description |
|---|---|
setCustomId(id) |
Unique ID for this field (used in getRequiredInputValue(); max 100 chars). Required: toJSON() throws without it. |
setLabel(label) |
The visible field label (max 45 chars). |
setStyle(style) |
TextInputType.Short (single line, the default) or TextInputType.Paragraph (multi-line). |
setRequired(required?) |
Whether the field is required (required defaults to true). |
setValue(value) |
Pre-filled default value (max 4000 chars). |
setPlaceholder(text) |
Placeholder text (max 100 chars). |
setMinLength(min) |
Minimum character length (0–4000). |
setMaxLength(max) |
Maximum character length (0–4000). toJSON() throws when min_length exceeds max_length. |
toJSON() |
Serializes the text input. |
Full Example
Section titled “Full Example”import { CreateModal, CreateActionRow, CreateTextInput, TextInputType,} from "lunibee";
// Build the modalconst modal = new CreateModal() .setCustomId("report_form") .setTitle("Report a User") .addComponents( new CreateActionRow<CreateTextInput>().addComponents( new CreateTextInput() .setCustomId("reported_user") .setLabel("Reported User ID or Username") .setStyle(TextInputType.Short) .setRequired(true), ), new CreateActionRow<CreateTextInput>().addComponents( new CreateTextInput() .setCustomId("reason") .setLabel("Reason for reporting") .setStyle(TextInputType.Paragraph) .setRequired(true) .setMaxLength(1000), ), );
// Show the modal in response to a commandclient.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "report") return; await interaction.showModal(modal);});
// Handle the modal submissionclient.on("interactionCreate", async (interaction) => { if (!interaction.isModalSubmit() || interaction.customId !== "report_form") return; const userId = interaction.getRequiredInputValue("reported_user"); const reason = interaction.getRequiredInputValue("reason"); await interaction.reply({ content: `📨 Report filed for **${userId}**: ${reason}`, ephemeral: true, });});import { CreateModal, CreateActionRow, CreateTextInput, TextInputType,} from "lunibee";
// Build the modalconst modal = new CreateModal() .setCustomId("report_form") .setTitle("Report a User") .addComponents( new CreateActionRow().addComponents( new CreateTextInput() .setCustomId("reported_user") .setLabel("Reported User ID or Username") .setStyle(TextInputType.Short) .setRequired(true), ), new CreateActionRow().addComponents( new CreateTextInput() .setCustomId("reason") .setLabel("Reason for reporting") .setStyle(TextInputType.Paragraph) .setRequired(true) .setMaxLength(1000), ), );
// Show the modal in response to a commandclient.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "report") return; await interaction.showModal(modal);});
// Handle the modal submissionclient.on("interactionCreate", async (interaction) => { if (!interaction.isModalSubmit() || interaction.customId !== "report_form") return; const userId = interaction.getRequiredInputValue("reported_user"); const reason = interaction.getRequiredInputValue("reason"); await interaction.reply({ content: `📨 Report filed for **${userId}**: ${reason}`, ephemeral: true, });});0.2.1 Additions
Section titled “0.2.1 Additions”addTextInputs(...inputs)
Section titled “addTextInputs(...inputs)”Adds text inputs, each in its own action row (the layout Discord requires), so you do not build the rows yourself. A modal holds at most five.
new CreateModal() .setCustomId("feedback") .setTitle("Feedback") .addTextInputs( new CreateTextInput().setCustomId("title").setLabel("Subject").setStyle(TextInputType.Short), new CreateTextInput().setCustomId("body").setLabel("Details").setStyle(TextInputType.Paragraph), );toJSON() is now typed with a required custom_id and title, matching what it validates.