skip to Main Content

I’m trying to make a series of 3 modals that ask the user questions, but when creating the modals it throws this error.

ValidationError: Expected the value to be a string or number
at NativeEnumValidator.handle (/node_modules/@sapphire/shapeshift/dist/index.js:1871:25)
at NativeEnumValidator.parse (/node_modules/@sapphire/shapeshift/dist/index.js:212:88)
at validateRequiredParameters (/node_modules/@discordjs/builders/dist/index.js:1063:27)
at TextInputBuilder.toJSON (/node_modules/@discordjs/builders/dist/index.js:1172:5)
at /node_modules/@discordjs/builders/dist/index.js:1285:64
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (/node_modules/@discordjs/builders/dist/index.js:1285:35)
at /node_modules/@discordjs/builders/dist/index.js:1374:64
at Array.map (<anonymous>)
at ModalBuilder.toJSON (/node_modules/@discordjs/builders/dist/index.js:1374:35) {
validator: 's.nativeEnum(T)',
given: undefined
}

This is the code that causes the error, which is meant to open a modal when a button is clicked. the modal is then meant to open another modal when submitted, which then opens another modal in order to get around the maximum of 5 action bars per modal. The responses are then put in an embed and sent to a channel that holds all staff applications to be accepted or denied.

collector.on('collect', async i => {
    if (i.customId != 'applications') return;
    const modal = new ModalBuilder().setTitle('Staff Application').setCustomId('applicationModal');
    const modal2 = new ModalBuilder().setTitle('Staff Application').setCustomId('applicationModal2');
    const modal3 = new ModalBuilder().setTitle('Staff Application').setCustomId('applicationModal3');
    const roleInput = new TextInputBuilder().setCustomId('roleInput').setLabel('Role').setPlaceholder('Developer, Moderator, Builder, etc.').setStyle(TextInputStyle.Short).setRequired(true);
    const ignInput = new TextInputBuilder().setCustomId('ignInput').setLabel('Minecraft Username').setStyle(TextInputStyle.Short).setRequired(true).setPlaceholder('Username');
    const question1 = new TextInputBuilder().setCustomId('question1').setLabel('Do you have a working mic?').setPlaceholder('Yes or no').setRequired(true);
    const question2 = new TextInputBuilder().setCustomId('question3').setLabel('How much time can you spend per week?').setStyle(TextInputStyle.Short).setRequired(true).setPlaceholder('___ hours');
    const question3 = new TextInputBuilder().setCustomId('question4').setLabel('Why should we choose you?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question4 = new TextInputBuilder().setCustomId('question5').setLabel('Why do you want to be staff?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question5 = new TextInputBuilder().setCustomId('question6').setLabel('What staff experience do you have?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question6 = new TextInputBuilder().setCustomId('question7').setLabel('What would you do if someone spammed chat?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question7 = new TextInputBuilder().setCustomId('question8').setLabel('What if someone impersonated staff?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question8 = new TextInputBuilder().setCustomId('question9').setLabel('What if someone was bigoted in chat?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question9 = new TextInputBuilder().setCustomId('question10').setLabel('What if someone were hacking/exploiting?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question10 = new TextInputBuilder().setCustomId('question11').setLabel('What if someone doxxed another user?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question11 = new TextInputBuilder().setCustomId('question12').setLabel('What if you saw someone abusing staff?').setStyle(TextInputStyle.Paragraph).setRequired(true).setPlaceholder('Paragraph');
    const question12 = new TextInputBuilder().setCustomId('question13').setLabel('Anything else you want us to know?').setStyle(TextInputStyle.Paragraph).setRequired(false).setPlaceholder('Paragraph');

    const modalRow = new ActionRowBuilder().addComponents(roleInput);
    const modalRow2 = new ActionRowBuilder().addComponents(ignInput);
    const modalRow3 = new ActionRowBuilder().addComponents(question1);
    const modalRow4 = new ActionRowBuilder().addComponents(question2);
    const modalRow5 = new ActionRowBuilder().addComponents(question3);
    const modalRow6 = new ActionRowBuilder().addComponents(question4);
    const modalRow7 = new ActionRowBuilder().addComponents(question5);
    const modalRow8 = new ActionRowBuilder().addComponents(question6);
    const modalRow9 = new ActionRowBuilder().addComponents(question7);
    const modalRow10 = new ActionRowBuilder().addComponents(question8);
    const modalRow11 = new ActionRowBuilder().addComponents(question9);
    const modalRow12 = new ActionRowBuilder().addComponents(question10);
    const modalRow13 = new ActionRowBuilder().addComponents(question11);
    const modalRow14 = new ActionRowBuilder().addComponents(question12);

    modal.addComponents(modalRow, modalRow2, modalRow3, modalRow4, modalRow5);
    modal2.addComponents(modalRow6, modalRow7, modalRow8, modalRow9, modalRow10);
    modal3.addComponents(modalRow11, modalRow12, modalRow13, modalRow14);
    await i.showModal(modal);
    client.on(Events.InteractionCreate, async interaction => {
        if (!interaction.isModalSubmit()) return;
        if (interaction.customId != 'applicationModal') return;
        interaction.showModal(modal2)
        client.on(Events.InteractionCreate, async interaction2 => {
            if (!interaction2.isModalSubmit()) return;
            if (interaction2.customId != 'applicationModal2') return;
            interaction2.showModal(modal3);
            client.on(Events.InteractionCreate, async interaction3 => {
                if (!interaction3.isModalSubmit()) return;
                if (interaction3.customId != 'applicationModal3') return;
                interaction3.reply({ content: 'Your application is being reviewed.', ephemeral: true });
                console.log('Application Recieved');
                const applicationEmbed = new EmbedBuilder().setTitle('Application').setDescription(`Application from ${interaction.user}`).setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() }).setThumbnail(interaction.user.displayAvatarURL()).addFields(
                    { name: 'Role', value: interaction.fields.getTextInputValue('roleInput') },
                    { name: 'Minecraft Username', value: interaction.fields.getTextInputValue('ignInput') },
                    { name: 'Do you have a working mic?', value: interaction.fields.getTextInputValue('question1') },
                    { name: 'How much time can you spend per week?', value: interaction.fields.getTextInputValue('question2') },
                    { name: 'Why should we choose you?', value: interaction2.fields.getTextInputValue('question3') },
                    { name: 'Why do you want to be staff?', value: interaction2.fields.getTextInputValue('question4') },
                    { name: 'What staff experience do you have?', value: interaction2.fields.getTextInputValue('question5') },
                    { name: 'What would you do if someone spammed chat?', value: interaction2.fields.getTextInputValue('question6') },
                    { name: 'What would you do if someone impersonated staff?', value: interaction2.fields.getTextInputValue('question7') },
                    { name: 'What would you do if someone was bigoted in chat?', value: interaction3.fields.getTextInputValue('question8') },
                    { name: 'What would you do if someone were hacking or using illegal exploits?', value: interaction3.fields.getTextInputValue('question9') },
                    { name: 'What would you do if someone doxxed another user?', value: interaction3.fields.getTextInputValue('question10') },
                    { name: 'What would you do if you saw someone abusing staff?', value: interaction3.fields.getTextInputValue('question11') },
                    { name: 'Anything else you want us to know?', value: interaction3.fields.getTextInputValue('question12') }
                ).setColor(0xc50549);
                await applicationChannel.send({ embeds: [applicationEmbed] });
                });
            });
        });
});

I tried checking all the customIDs and names, as those often cause the "Expected…" errors that I see, but could not see anything that looked like it was causing the issue. One of my main issues is the fact that it is not telling me where in the code the error is coming from specifically. After logging to the console after sections of the code are completed, I have found that the error arises when showing the first modal, but not while creating it.

2

Answers


  1. Chosen as BEST ANSWER

    While I found a way to resolve this error by replacing the first client.on(Events.InteractionCreate) with i.awaitModalSubmit(), it now says that that is not a function while it is listed as a function of both a MessageComponentInteraction and a ButtonInteraction, which i should be one of.


  2. const roleInput = new TextInputBuilder().setCustomId('roleInput').setPlaceholder('Developer, Moderator, Builder, etc.').setRequired(true);

    maybe need setLabel()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search