Whenever I run my code I get an odd error from my slash command file here is the error. I have checked for capital names in the slash command and my command handler though I cant seem to figure it out perhaps you can help me?
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [],
"message": "Required"
}
]
at handleResult (/home/runner/MI6Agent/node_modules/zod/lib/types.js:28:23)
at ZodString.safeParse (/home/runner/MI6Agent/node_modules/zod/lib/types.js:140:16)
at ZodString.parse (/home/runner/MI6Agent/node_modules/zod/lib/types.js:120:29)
at Y (/home/runner/MI6Agent/node_modules/@discordjs/builders/dist/index.js:3:5798)
at b (/home/runner/MI6Agent/node_modules/@discordjs/builders/dist/index.js:3:5893)
at te.runRequiredValidations (/home/runner/MI6Agent/node_modules/@discordjs/builders/dist/index.js:3:6930)
at te.toJSON (/home/runner/MI6Agent/node_modules/@discordjs/builders/dist/index.js:3:7116)
at /home/runner/MI6Agent/node_modules/@discordjs/builders/dist/index.js:3:12954
at Array.map (<anonymous>)
at MixedClass.toJSON (/home/runner/MI6Agent/node_modules/@discordjs/builders/dist/index.js:3:12945)
at /home/runner/MI6Agent/node_modules/@discordjs/builders/dist/index.js:3:13239
at Array.map (<anonymous>)
at MixedClass.toJSON (/home/runner/MI6Agent/node_modules/@discordjs/builders/dist/index.js:3:13230)
at Object.<anonymous> (/home/runner/MI6Agent/index.js:33:30)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
Here is my slash command.
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('inform')
.setDescription('Informs the specified user in DMs.')
.addSubcommand(command => command
.setName('channel')
.setDescription('Sends a message to an channel')
.addChannelOption(option => option.setName('target').setDescription('Select the target channel').setRequired(true)).addBooleanOption(option => option.setName('incognito').setRequired(true)))
.addSubcommand(command => command
.setName('member')
.setDescription('Sends a message to an member')
.addUserOption(option => option.setName('target').setDescription('Select the target user').setRequired(true)).addBooleanOption(option => option.setName('incognito').setRequired(true)))
.addSubcommand(command => command
.setName('role')
.setDescription('Sends a message to an member')
.addRoleOption(option => option.setName('target').setDescription('Select the target role').setRequired(true)).addBooleanOption(option => option.setName('incognito').setRequired(true))),
}
There's a hint in the error: it received undefined but expected a string. This means you're missing something (rather than something being an invalid string e.g. with capital letters).
You need to add descriptions for the incognito boolean option (add a .setDescription() to the method chain).
For more information on what fields are required for commands and their options, see the Discord API docs.