Discord.js子命令和子命令组选项类型与所有其他类型互斥。

huangapple go评论79阅读模式
英文:

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.

英文:

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.

答案1

得分: 1

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),
      ),
  ),
英文:

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),
      ),
  ),

huangapple
  • 本文由 发表于 2023年6月30日 02:14:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76583660.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定