Discord JS 斜杠命令 zodError?

Discord JS slash command zodError?

每当我 运行 我的代码我从我的斜杠命令文件中得到一个奇怪的错误,这里是错误。 我已经检查了斜杠命令和我的命令处理程序中的大写名称,但我似乎无法弄清楚也许你可以帮助我?

  {
    "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) 

这是我的斜杠命令。

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))),
}

错误中有一个提示:它收到了 undefined 但需要一个字符串。这意味着您遗漏了一些东西(而不是一些无效的字符串,例如大写字母)。

您需要为 incognito 布尔选项添加说明(向方法链添加 .setDescription())。

有关命令及其选项所需字段的详细信息,请参阅 Discord API docs