Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

512
Views
Slash command not registered - DiscordAPIError: Invalid Form Body, 0.options[2].type: This field is required

I have a Discord bot that has a slash command; /info. My intention is to have a subcommand - server - execute without needing to specify a value.

This code, however, does not allow me to do that. It instead throws an error upon bot startup.

const { Client, CommandInteraction } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
    ...new SlashCommandBuilder()
    .setName("info")
    .setDescription("Displays information regarding the current server or specified user")
    .addUserOption((option) => option
        .setName("user")
        .setDescription("Displays information regarding the specified user")
    )
    .addUserOption((option) => option
        .setName("member")
        .setDescription("Displays information regarding the specified guild member")
    )
    .addSubcommand((subcommand) => subcommand
        .setName("server")
        .setDescription("Displays information regarding the current server")
    ),
// ...

Error

F:\GitHub\Discord Bots\Bailey-v4\node_modules\discord.js\src\rest\RequestHandler.js:350
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Invalid Form Body
0.options[2].type: This field is required
    at RequestHandler.execute (F:\GitHub\Discord Bots\Bailey-v4\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (F:\GitHub\Discord Bots\Bailey-v4\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async GuildApplicationCommandManager.set (F:\GitHub\Discord Bots\Bailey-v4\node_modules\discord.js\src\managers\ApplicationCommandManager.js:146:18)
    at async Client.<anonymous> (F:\GitHub\Discord Bots\Bailey-v4\handler\index.js:44:9)

Assistance (in any) would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't think you can mix the addSubcommand() method with other methods like addUserOption(). Sub-command and sub-command group option types are mutually exclusive to all other types.

To solve this, you will need to set up two more sub commands:

new SlashCommandBuilder()
  .setName('info')
  .setDescription(
    'Displays information regarding the current server or specified user',
  )
  .addSubcommand((subcommand) =>
    subcommand
      .setName('user')
      .setDescription('Displays information regarding the specified user')
      .addUserOption((option) =>
        option.setName('target')
          .setDescription('The user')
          .setRequired(true),
      ),
  )
  .addSubcommand((subcommand) =>
    subcommand
      .setName('member')
      .setDescription('Displays information regarding the specified guild member')
      .addUserOption((option) =>
        option
          .setName('target')
          .setDescription('The member')
          .setRequired(true),
      ),
  )
  .addSubcommand((subcommand) =>
    subcommand
      .setName('server')
      .setDescription('Displays information regarding the current server'),
  )

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!