Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

DiscordJS v14 invalid form body

I have been trying to make a slash command with subcommand that sends message to specified channel.
When i try to deploy it, i get:

DiscordAPIError[50035]: Invalid Form Body
options[1][APPLICATION_COMMAND_OPTIONS_TYPE_INVALID]: Sub-command and sub-command group option types are mutually exclusive to all other types
    at SequentialHandler.runRequest (D:\projs\cpp\tbot\node_modules\@discordjs\rest\dist\index.js:659:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SequentialHandler.queueRequest (D:\projs\cpp\tbot\node_modules\@discordjs\rest\dist\index.js:458:14)
    at async REST.request (D:\projs\cpp\tbot\node_modules\@discordjs\rest\dist\index.js:902:22)
    at async D:\projs\cpp\tbot\deploy-commands.js:24:16 {
  requestBody: { files: undefined, json: [ [Object], [Object] ] },
  rawError: {
    code: 50035,
    errors: { options: [Object] },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'PUT',
  url: 'https://discord.com/api/v10/applications/752621311494455367/guilds/1039125828790919240/commands'
}

My code:

const { SlashCommandBuilder } = require('discord.js');

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

module.exports = {
    data: new SlashCommandBuilder()
        .setName('say')
        .setDescription('Make bot say anything the executor wants')
        .addSubcommand(subcommand =>
            subcommand
                .setName('channel')
                .setDescription('Says ')
             .addChannelOption(option =>
                  option
                    .setName('target_channel')
                    .setDescription('Channel to send message in.')
                    .setRequired(true)))
              .addStringOption(option =>
                option
                    .setName('text')
                    .setDescription("Message to be sent in specified channel")
                    .setRequired(true)),
    async execute(interaction) {
        const channel = interaction.options.getChannel('target_channel');
        const text = interaction.options.getString('text');

        client.channels.cache.get(channel).send(text);
    },
};

I have no clue about it. I didn’t find anything about it anywhere. I expected it to deploy the commands via node deploy-commands.js but it resulted in error above.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The error is emitted when you attempt to add an option to a command which also has a subcommand. To illustrate this better I’ve create an ascii table, note how channel and text options are on the same level, which would result in an error.

say
 |- channel: SUB_COMMAND
 |   |- name: STRING
 |   |- target_channel: TEXTCHANNEL
 |- text: STRING
 |   |- option: STRING

If I’ve interpreted your code correctly you may want to add the string option to the subcommand, as so:

data: new SlashCommandBuilder()
    .setName('say')
    .setDescription('Make bot say anything the executor wants')
    .addSubcommand(subcommand =>
        subcommand
            .setName('channel')
            .setDescription('Says ')
            .addStringOption(option =>
                option
                    .setName('text')
                    .setDescription("Message to be sent in specified channel")
                    .setRequired(true)
            )
            .addChannelOption(option =>
                option
                    .setName('target_channel')
                    .setDescription('Channel to send message in.')
                    .setRequired(true)
            )
    )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading