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!
1 answer
-
answered 2022-01-19 17:05
Zsolt Meszaros
I don't think you can mix the
addSubcommand()
method with other methods likeaddUserOption()
. 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'), )
How many English words
do you know?
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
how many words do you know
Powered by Examplum