Tengo un bot de Discord que tiene un comando de barra; /info . Mi intención es tener un subcomando ( server ) ejecutado sin necesidad de especificar un valor.
Este código, sin embargo, no me permite hacer eso. En su lugar, arroja un error al iniciar el bot.
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)¡La ayuda (en cualquiera) sería muy apreciada!
No creo que puedas mezclar el método addSubcommand() con otros métodos como addUserOption() . Los tipos de opciones de subcomandos y grupos de subcomandos son mutuamente excluyentes para todos los demás tipos.
Para resolver esto, deberá configurar dos subcomandos más:
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'), )