Skip to content
Advertisement

Discord.js Modal ValidationError

I’m attempting to make a bot but when I try to show the user a modal, I get the following error:

ValidationError: Expected the value to be a string or number

I’m not sure why this happens, but here is the code which seems to be causing it:

await interaction2.showModal(
  new ModalBuilder()
    .setTitle("Create new field.")
    .setCustomId("newtemplatefield")
    .setComponents(
      ...[
        new ActionRowBuilder<TextInputBuilder>().addComponents(
          ...[
            new TextInputBuilder().setLabel("Field Name").setCustomId("fieldname").setRequired(true)
          ]
        ),
        new ActionRowBuilder<TextInputBuilder>().addComponents(
          ...[
            new TextInputBuilder()
              .setLabel("Field Description")
              .setCustomId("fielddesc")
              .setRequired(true)
          ]
        )
      ]
    )
);

Advertisement

Answer

Discord.js error messages leave a lot to be desired, but the validation error is really a missing required part of the text input. You need to set the TextInputStyle with .setStyle(TextInputStyle.Short) or .setStyle(TextInputStyle.Paragraph)

Check out the sample modal in the Discord.js docs.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement