skip to Main Content

There are 30 data in the json file. But the choices section for the discord bot is limited to 25. How can I solve this? I am using Node.js Discord.js.

const currencyData = require("../../json/commands/currency.json");
const currencyChocies = currencyData.currency;
module.exports = {
  deleted: false,
  name: "pricecurrency",
  description: "Currency Price",
  type: ApplicationCommandOptionType.String,
  // devOnly: Boolean,
  // testOnly: Boolean,
  options: [
    {
      name: "currency",
      description: "currency name",
      type: ApplicationCommandOptionType.String,
      choices: currencyChocies,
      required: true,
    },
  ],
  callback: async (client, interaction) => {
    const currencyName = interaction.options.getString("currency");
    try {
      const data = await fetchCurrencyData("Currency");
      const desiredCurrency = data.find(
        (item) => item.detailsId === currencyName
      );

      if (desiredCurrency) {
        const chaosEquivalent = desiredCurrency.chaosEquivalent;
        const currencyTypeName = desiredCurrency.currencyTypeName;
        interaction.reply(
          "Name:" + currencyTypeName + "  Chaos Price:" + chaosEquivalent
        );
      } else {
        interaction.reply("Nothing Found Currency");
      }
    } catch (error) {
      console.log(error);
      await interaction.reply("API Error");
    }
  },
};

Error:

TThere was an error: DiscordAPIError[50035]: Invalid Form Body
options[0].choices[BASE_TYPE_MAX_LENGTH]: Must be 25 or fewer in length.

I tried sorting but I didn’t use it in the structure. Is there a method in Nodejs that can help?

2

Answers


  1. Check out autocomplete. Here’s the link to the usage guide. After a user submits the command you can verify that the currency they selected is real and is in the list of possible options.

    Here’s a modified version of their example that fits your needs:

        async autocomplete(interaction) {
            const focusedValue = interaction.options.getFocused();
            const filtered = currencyChoices.filter(choice => choice.startsWith(focusedValue));
            await interaction.respond(
                filtered.map(choice => ({ name: choice, value: choice })),
            );
        },
    

    Add that to your module.exports along with the code that handles the rest of the autocomplete process found in the documentation.

    Don’t forget to enable autocomplete for your command.

    Login or Signup to reply.
  2. Actually 25 options is the maximum for a slash command.

    Discord docs image

    You can see this here

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