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

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

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:

  1. const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
  2. const { warningSchema } = require('../models/warnings.js')
  3. module.exports = {
  4. data: new SlashCommandBuilder()
  5. .setName('warnings')
  6. .setDescription('complete warning system')
  7. .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers)
  8. .addSubcommand((subcommand) =>
  9. subcommand.setName('add')
  10. .setDescription('add a warning to an user')
  11. .addUserOption((option) =>
  12. option.setName('user')
  13. .setDescription('user to warn')
  14. .setRequired(true))
  15. .addStringOption((option) =>
  16. option.setName('reason')
  17. .setDescription('reason to warn')
  18. .setRequired(false)))
  19. .addStringOption((option) =>
  20. option.setName('evidence')
  21. .setDescription('evidence to warn')
  22. .setRequired(false))
  23. .addSubcommand((subcommand) =>
  24. subcommand.setName('check')
  25. .setDescription('check warnings of an user')
  26. .addUserOption((option) =>
  27. option.setName('user')
  28. .setDescription('user to warn')
  29. .setRequired(true)))
  30. .addSubcommand((subcommand) =>
  31. subcommand.setName('remove')
  32. .setDescription('remove a specific warning of an user')
  33. .addUserOption((option) =>
  34. option.setName('user')
  35. .setDescription('user to warn')
  36. .setRequired(true))
  37. .addStringOption((option) =>
  38. option.setName('id')
  39. .setDescription('target warning')
  40. .setRequired(true)))
  41. .addSubcommand((subcommand) =>
  42. subcommand.setName('clear')
  43. .setDescription('clear all warnings of an user')
  44. .addUserOption((option) =>
  45. option.setName('user')
  46. .setDescription('user to warn')
  47. .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:

  1. const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js');
  2. const { warningSchema } = require('../models/warnings.js')
  3. module.exports = {
  4. data: new SlashCommandBuilder()
  5. .setName('warnings')
  6. .setDescription('complete warning system')
  7. .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers)
  8. .addSubcommand((subcommand) =>
  9. subcommand.setName('add')
  10. .setDescription('add a warning to an user')
  11. .addUserOption((option) =>
  12. option.setName('user')
  13. .setDescription('user to warn')
  14. .setRequired(true))
  15. .addStringOption((option) =>
  16. option.setName('reason')
  17. .setDescription('reason to warn')
  18. .setRequired(false)))
  19. .addStringOption((option) =>
  20. option.setName('evidence')
  21. .setDescription('evidence to warn')
  22. .setRequired(false))
  23. .addSubcommand((subcommand) =>
  24. subcommand.setName('check')
  25. .setDescription('check warnings of an user')
  26. .addUserOption((option) =>
  27. option.setName('user')
  28. .setDescription('user to warn')
  29. .setRequired(true)))
  30. .addSubcommand((subcommand) =>
  31. subcommand.setName('remove')
  32. .setDescription('remove a specific warning of an user')
  33. .addUserOption((option) =>
  34. option.setName('user')
  35. .setDescription('user to warn')
  36. .setRequired(true))
  37. .addStringOption((option) =>
  38. option.setName('id')
  39. .setDescription('target warning')
  40. .setRequired(true)))
  41. .addSubcommand((subcommand) =>
  42. subcommand.setName('clear')
  43. .setDescription('clear all warnings of an user')
  44. .addUserOption((option) =>
  45. option.setName('user')
  46. .setDescription('user to warn')
  47. .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:

  1. data: new SlashCommandBuilder()
  2. .setName('warnings')
  3. .setDescription('complete warning system')
  4. .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers)
  5. .addSubcommand((subcommand) =>
  6. subcommand
  7. .setName('add')
  8. .setDescription('add a warning to an user')
  9. .addUserOption((option) =>
  10. option
  11. .setName('user')
  12. .setDescription('user to warn')
  13. .setRequired(true),
  14. )
  15. .addStringOption((option) =>
  16. option
  17. .setName('reason')
  18. .setDescription('reason to warn')
  19. .setRequired(false),
  20. )
  21. .addStringOption((option) =>
  22. option
  23. .setName('evidence')
  24. .setDescription('evidence to warn')
  25. .setRequired(false),
  26. ),
  27. )
  28. .addSubcommand((subcommand) =>
  29. subcommand
  30. .setName('check')
  31. .setDescription('check warnings of an user')
  32. .addUserOption((option) =>
  33. option
  34. .setName('user')
  35. .setDescription('user to warn')
  36. .setRequired(true),
  37. ),
  38. )
  39. .addSubcommand((subcommand) =>
  40. subcommand
  41. .setName('remove')
  42. .setDescription('remove a specific warning of an user')
  43. .addUserOption((option) =>
  44. option
  45. .setName('user')
  46. .setDescription('user to warn')
  47. .setRequired(true),
  48. )
  49. .addStringOption((option) =>
  50. option
  51. .setName('id')
  52. .setDescription('target warning')
  53. .setRequired(true),
  54. ),
  55. )
  56. .addSubcommand((subcommand) =>
  57. subcommand
  58. .setName('clear')
  59. .setDescription('clear all warnings of an user')
  60. .addUserOption((option) =>
  61. option
  62. .setName('user')
  63. .setDescription('user to warn')
  64. .setRequired(true),
  65. ),
  66. ),
英文:

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:

  1. data: new SlashCommandBuilder()
  2. .setName('warnings')
  3. .setDescription('complete warning system')
  4. .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers)
  5. .addSubcommand((subcommand) =>
  6. subcommand
  7. .setName('add')
  8. .setDescription('add a warning to an user')
  9. .addUserOption((option) =>
  10. option
  11. .setName('user')
  12. .setDescription('user to warn')
  13. .setRequired(true),
  14. )
  15. .addStringOption((option) =>
  16. option
  17. .setName('reason')
  18. .setDescription('reason to warn')
  19. .setRequired(false),
  20. )
  21. .addStringOption((option) =>
  22. option
  23. .setName('evidence')
  24. .setDescription('evidence to warn')
  25. .setRequired(false),
  26. ),
  27. )
  28. .addSubcommand((subcommand) =>
  29. subcommand
  30. .setName('check')
  31. .setDescription('check warnings of an user')
  32. .addUserOption((option) =>
  33. option
  34. .setName('user')
  35. .setDescription('user to warn')
  36. .setRequired(true),
  37. ),
  38. )
  39. .addSubcommand((subcommand) =>
  40. subcommand
  41. .setName('remove')
  42. .setDescription('remove a specific warning of an user')
  43. .addUserOption((option) =>
  44. option
  45. .setName('user')
  46. .setDescription('user to warn')
  47. .setRequired(true),
  48. )
  49. .addStringOption((option) =>
  50. option
  51. .setName('id')
  52. .setDescription('target warning')
  53. .setRequired(true),
  54. ),
  55. )
  56. .addSubcommand((subcommand) =>
  57. subcommand
  58. .setName('clear')
  59. .setDescription('clear all warnings of an user')
  60. .addUserOption((option) =>
  61. option
  62. .setName('user')
  63. .setDescription('user to warn')
  64. .setRequired(true),
  65. ),
  66. ),

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:

确定