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!