Working with the components in Modals

I’ve gone through everything now, and I’m still not really sure. Discord has now brought components to modals as well, like Selects, etc. However, I can’t really find any code examples or how to properly implement them. I’ve sent an example above showing how it currently looks for me. Now I want to add Selects too, but I’m not sure how to do it.
const { SlashCommandBuilder } = require('@discordjs/builders');
const { ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require('discord.js');

module.exports = {
dev: true,
owner: true,
data: new SlashCommandBuilder()
.setName('namemodal')
.setDescription('Test'),
async execute(interaction) {
const modal = new ModalBuilder()
.setCustomId('name_modal')
.setTitle('Enter Your Name');

const nameInput = new TextInputBuilder()
.setCustomId('person_name')
.setLabel('What is your name?')
.setStyle(TextInputStyle.Short)
.setRequired(true);

modal.addComponents(
new ActionRowBuilder().addComponents(nameInput)
);

if (typeof interaction.showModal === 'function') {
await interaction.showModal(modal);
}
}
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require('discord.js');

module.exports = {
dev: true,
owner: true,
data: new SlashCommandBuilder()
.setName('namemodal')
.setDescription('Test'),
async execute(interaction) {
const modal = new ModalBuilder()
.setCustomId('name_modal')
.setTitle('Enter Your Name');

const nameInput = new TextInputBuilder()
.setCustomId('person_name')
.setLabel('What is your name?')
.setStyle(TextInputStyle.Short)
.setRequired(true);

modal.addComponents(
new ActionRowBuilder().addComponents(nameInput)
);

if (typeof interaction.showModal === 'function') {
await interaction.showModal(modal);
}
}
};
6 Replies
d.js toolkit
d.js toolkit2mo ago
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2mo ago
documentation suggestion for @Finjan: :method: ModalBuilder#addLabelComponents() builders@1.12.1 Adds label components to this modal.
Amgelo
Amgelo2mo ago
and LabelBuilder has addXSelectMenuComponent methods
Finjan
FinjanOP2mo ago
Ez thank you very much
d.js toolkit
d.js toolkit2mo ago
The thread owner has marked this issue as solved.

Did you find this page helpful?