Max 45 characters
Used to identify the modal in your code
10-1000 characters
// Discord.js - Show Modal
const { ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require('discord.js');
// Create the modal
const modal = new ModalBuilder()
.setCustomId('feedback_modal')
.setTitle('Feedback Form');
// Text Input 1
const feedback_input = new TextInputBuilder()
.setCustomId('feedback_input')
.setLabel('What is your feedback?')
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('Enter your feedback here...')
.setRequired(true)
.setMinLength(10)
.setMaxLength(1000);
const row1 = new ActionRowBuilder().addComponents(feedback_input);
// Add inputs to the modal
modal.addComponents(row1);
// Show the modal
await interaction.showModal(modal);// Discord.js - Handle Modal Submission
client.on('interactionCreate', async (interaction) => {
if (!interaction.isModalSubmit()) return;
if (interaction.customId !== 'feedback_modal') return;
// Get the values from the modal
const feedback_input = interaction.fields.getTextInputValue('feedback_input');
// Process the data
console.log('Modal submitted:');
console.log('What is your feedback?:', feedback_input);
// Send response
await interaction.reply({
content: 'Thank you for your submission!',
ephemeral: true
});
});