You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行node src/register-commands.js时必填命令选项位置错误问题咨询

修复options[1][APPLICATION_COMMAND_OPTIONS_REQUIRED_INVALID]错误

执行node src/register-commands.js时触发该错误,核心原因是Discord命令规则要求必填选项必须放在非必填选项之前。

你的代码里,second-number选项设置了required: true(必填),但它被放在了未声明required的first-number(非必填)后面,违反了顺序规则。

修复步骤

  1. 调换选项顺序,将必填的second-number移到非必填的first-number前面
  2. 补全代码中缺失的闭合括号(原代码未完成)

修复后的完整代码

const commands = [
    {
        name: 'add',
        description: 'Adds two numbers', 
        options: [
            {
                name: 'second-number', 
                description: 'The second number.', 
                type: ApplicationCommandOptionType.Number,
                required: true,
            },
            {
                name: 'first-number', 
                description: 'The first number', 
                type: ApplicationCommandOptionType.Number,
                choices:  [
                    {
                        name: 'one',
                        value: 1,
                    },
                    {
                        name: 'two',
                        value: 2,
                    },
                    {
                        name: 'three',
                        value: 3,
                    }
                ]
            }
        ]
    }
];

调整后重新执行node src/register-commands.js,命令即可正常注册。

内容的提问来源于stack exchange,提问作者iimonkeyxs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 07:52:12