【问题标题】:Integer option does not work (discord.js v14)整数选项不起作用(discord.js v14)
【发布时间】:2022-11-25 13:58:18
【问题描述】:

所以我正在尝试使用 .addOptionInteger 选项,但它不起作用

.setName('add')
    .setDescription('Add coins to your current balance')
        .addIntegerOption(option =>
            option.setName("amount")
                .setDescription("amount of coins")
                .setMinValue(0)
                .setMaxValue(22)
                ),

这是为了获取它

const AddCoins = options.getInteger('amount');

但它一直给我这个错误:

Error: TypeError [CommandInteractionOptionType]: Option "amount" is of type: 3; expected 4.

我试图查看 discordjs 文档,但只有关于 String 等选项的内容。

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    此错误的根源不在斜杠命令生成器中,而是您在代码中获取命令参数的方式。

    即你可能在某个地方使用<CommandInteractionOptionResolver>#getString而不是<CommandInteractionOptionResolver>#getInteger

    不要忘记 <CommandInteractionOptionResolver>#get 方法解析 CommandInteractionOption typedef,它有一个 value 属性保存所述参数的值(使用打字稿时确保转换正确的类型。)
    <CommandInteractionOptionsResolver>#get
    <CommandInteractionOption>

    您在 discord.js 库中的错误的确切来源可以查看here

    【讨论】:

      猜你喜欢
      • 2022-10-14
      • 2022-12-05
      • 2022-12-14
      • 2022-11-11
      • 2019-09-23
      • 2021-10-13
      • 1970-01-01
      • 2022-10-13
      • 2018-04-24
      相关资源
      最近更新 更多