Problem with Modal Builders

node:events:497 throw er; // Unhandled 'error' event ^ DiscordAPIError[50035]: Invalid Form Body data.custom_id[BASE_TYPE_REQUIRED]: This field is required data.title[BASE_TYPE_REQUIRED]: This field is required data.components[BASE_TYPE_REQUIRED]: This field is required at handleErrors (/Users/nils/development/discord-bot/node_modules/@discordjs/rest/dist/index.js:722:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async BurstHandler.runRequest (/Users/nils/development/discord-bot/node_modules/@discordjs/rest/dist/index.js:826:23) at async _REST.request (/Users/nils/development/discord-bot/node_modules/@discordjs/rest/dist/index.js:1266:22) at async ButtonInteraction.showModal (/Users/nils/development/discord-bot/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:253:5) at async Client.<anonymous> (/Users/nils/development/discord-bot/src/index.js:82:3) Emitted 'error' event on Client instance at: at emitUnhandledRejectionOrErr (node:events:402:10) at process.processTicksAndRejections (node:internal/process/task_queues:84:21) { requestBody: { files: undefined, json: { type: 9, data: {} } }, rawError: { message: 'Invalid Form Body', code: 50035, errors: { data: { custom_id: { _errors: [ [Object] ] }, title: { _errors: [ [Object] ] }, components: { _errors: [ [Object] ] } } } }, code: 50035, status: 400, method: 'POST', }
async function openVerifyModal() {
const modal = new ModalBuilder()
.setCustomId('verify_modal')
.setTitle('Verifizierung');

const firstName = new TextInputBuilder()
.setCustomId('verify_modal_first_name')
.setLabel('Vorname')
.setPlaceholder('Mazhor')
.setStyle('Short');

const lastName = new TextInputBuilder()
.setCustomId('verify_modal_last_name')
.setLabel('Nachname')
.setPlaceholder('Gaming')
.setStyle('Short');

const id = new TextInputBuilder()
.setCustomId('verify_modal_id')
.setLabel('GID')
.setPlaceholder('1')
.setStyle('Short');

const actionRow = new ActionRowBuilder()
.addComponents(firstName);

const secondActionRow = new ActionRowBuilder()
.addComponents(lastName);

const thirdActionRow = new ActionRowBuilder()
.addComponents(id);

modal.addComponents(actionRow, secondActionRow, thirdActionRow);

return modal;
}
async function openVerifyModal() {
const modal = new ModalBuilder()
.setCustomId('verify_modal')
.setTitle('Verifizierung');

const firstName = new TextInputBuilder()
.setCustomId('verify_modal_first_name')
.setLabel('Vorname')
.setPlaceholder('Mazhor')
.setStyle('Short');

const lastName = new TextInputBuilder()
.setCustomId('verify_modal_last_name')
.setLabel('Nachname')
.setPlaceholder('Gaming')
.setStyle('Short');

const id = new TextInputBuilder()
.setCustomId('verify_modal_id')
.setLabel('GID')
.setPlaceholder('1')
.setStyle('Short');

const actionRow = new ActionRowBuilder()
.addComponents(firstName);

const secondActionRow = new ActionRowBuilder()
.addComponents(lastName);

const thirdActionRow = new ActionRowBuilder()
.addComponents(id);

modal.addComponents(actionRow, secondActionRow, thirdActionRow);

return modal;
}
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isButton()) return;

if (interaction.customId === 'verify_button') {
console.log('Opening verify modal...');
console.log(openVerifyModal());
await interaction.showModal(openVerifyModal());
}
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isButton()) return;

if (interaction.customId === 'verify_button') {
console.log('Opening verify modal...');
console.log(openVerifyModal());
await interaction.showModal(openVerifyModal());
}
});
why this wont work?
2 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Nils
NilsOP9mo ago
ok
.then(async (modalInteraction) => {
const firstNameValue = modalInteraction.fields.getTextInputValue('verify_first_name');
const lastNameValue = modalInteraction.fields.getTextInputValue('verify_last_name');
const idValue = modalInteraction.fields.getTextInputValue('verify_id');

const embed = new EmbedBuilder()
.setTitle('Verifizierungs Anfrage')
.setDescription('' +
'**Vorname: **' + firstNameValue +
'**Nachname: **' + lastNameValue +
'**ID: **' + idValue,
);

const button = new ButtonBuilder()
.setCustomId('accept_verification')
.setStyle('Success')
.setLabel('Akzeptieren');

const channel = await client.channels.fetch('1224773916279439430').then();
await channel.send({
embeds: [embed],
});
}).catch(console.error);
.then(async (modalInteraction) => {
const firstNameValue = modalInteraction.fields.getTextInputValue('verify_first_name');
const lastNameValue = modalInteraction.fields.getTextInputValue('verify_last_name');
const idValue = modalInteraction.fields.getTextInputValue('verify_id');

const embed = new EmbedBuilder()
.setTitle('Verifizierungs Anfrage')
.setDescription('' +
'**Vorname: **' + firstNameValue +
'**Nachname: **' + lastNameValue +
'**ID: **' + idValue,
);

const button = new ButtonBuilder()
.setCustomId('accept_verification')
.setStyle('Success')
.setLabel('Akzeptieren');

const channel = await client.channels.fetch('1224773916279439430').then();
await channel.send({
embeds: [embed],
});
}).catch(console.error);
DiscordAPIError[50035]: Invalid Form Body components[0][UNION_TYPE_CHOICES]: Value of field "type" must be one of (1,). at handleErrors (/Users/nils/development/discord-bot/node_modules/@discordjs/rest/dist/index.js:722:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async SequentialHandler.runRequest (/Users/nils/development/discord-bot/node_modules/@discordjs/rest/dist/index.js:1120:23) at async SequentialHandler.queueRequest (/Users/nils/development/discord-bot/node_modules/@discordjs/rest/dist/index.js:953:14) at async _REST.request (/Users/nils/development/discord-bot/node_modules/@discordjs/rest/dist/index.js:1266:22) at async TextChannel.send (/Users/nils/development/discord-bot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:155:15) at async /Users/nils/development/discord-bot/src/index.js:89:5 { requestBody: { files: [], json: { content: undefined, tts: false, nonce: undefined, embeds: [Array], components: [Array], username: undefined, avatar_url: undefined, allowed_mentions: undefined, flags: undefined, message_reference: undefined, attachments: undefined, sticker_ids: undefined, thread_name: undefined } }, rawError: { message: 'Invalid Form Body', code: 50035, errors: { components: [Object] } }, code: 50035, status: 400, method: 'POST', url: 'https://discord.com/api/v10/channels/1224773916279439430/messages' } but what is here the problem it comes when i make channel.send() @Qjuh
Want results from more Discord servers?
Add your server