Search code examples
javascriptnode.jsdiscorddiscord.jsbots

Discord.js Sub-command and sub-command group option types are mutually exclusive to all other types


I get this error that I really did not understand what it means. Does it say that I can't add options to sub-commands or something?

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

Here is my code:

const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
const { warningSchema } = require('../models/warnings.js')
module.exports = {
    data: new SlashCommandBuilder()
        .setName('warnings')
        .setDescription('complete warning system')
        .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers)
        .addSubcommand((subcommand) => 
            subcommand.setName('add')
                .setDescription('add a warning to an user')
                .addUserOption((option) => 
                    option.setName('user')
                        .setDescription('user to warn')
                        .setRequired(true))
                .addStringOption((option) => 
                    option.setName('reason')
                        .setDescription('reason to warn')
                        .setRequired(false)))
                .addStringOption((option) => 
                    option.setName('evidence')
                        .setDescription('evidence to warn')
                        .setRequired(false))
        .addSubcommand((subcommand) => 
            subcommand.setName('check')
                .setDescription('check warnings of an user')
                .addUserOption((option) => 
                    option.setName('user')
                        .setDescription('user to warn')
                        .setRequired(true)))
        .addSubcommand((subcommand) => 
            subcommand.setName('remove')
                .setDescription('remove a specific warning of an user')
                .addUserOption((option) => 
                    option.setName('user')
                        .setDescription('user to warn')
                        .setRequired(true))
                .addStringOption((option) => 
                    option.setName('id')
                        .setDescription('target warning')
                        .setRequired(true)))
        .addSubcommand((subcommand) => 
            subcommand.setName('clear')
                .setDescription('clear all warnings of an user')
                .addUserOption((option) => 
                    option.setName('user')
                        .setDescription('user to warn')
                        .setRequired(true))),

I tried to make sub-commands but got an error that I can't understand.


Solution

  • It seems that you have misplaced the closing parenthesis for the first subcommand (where you try to add option.setName('evidence')).

    You cannot mix the addSubcommand() method with other methods like addStringOption(). Sub-command and sub-command group option types are mutually exclusive to all other types.

    The closing parenthesis should come after the "evidence" string option, not after the "reason" string option:

    data: new SlashCommandBuilder()
      .setName('warnings')
      .setDescription('complete warning system')
      .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers)
      .addSubcommand((subcommand) =>
        subcommand
          .setName('add')
          .setDescription('add a warning to an user')
          .addUserOption((option) =>
            option
              .setName('user')
              .setDescription('user to warn')
              .setRequired(true),
          )
          .addStringOption((option) =>
            option
              .setName('reason')
              .setDescription('reason to warn')
              .setRequired(false),
          )
          .addStringOption((option) =>
            option
              .setName('evidence')
              .setDescription('evidence to warn')
              .setRequired(false),
          ),
      )
      .addSubcommand((subcommand) =>
        subcommand
          .setName('check')
          .setDescription('check warnings of an user')
          .addUserOption((option) =>
            option
              .setName('user')
              .setDescription('user to warn')
              .setRequired(true),
          ),
      )
      .addSubcommand((subcommand) =>
        subcommand
          .setName('remove')
          .setDescription('remove a specific warning of an user')
          .addUserOption((option) =>
            option
              .setName('user')
              .setDescription('user to warn')
              .setRequired(true),
          )
          .addStringOption((option) =>
            option
              .setName('id')
              .setDescription('target warning')
              .setRequired(true),
          ),
      )
      .addSubcommand((subcommand) =>
        subcommand
          .setName('clear')
          .setDescription('clear all warnings of an user')
          .addUserOption((option) =>
            option
              .setName('user')
              .setDescription('user to warn')
              .setRequired(true),
          ),
      ),