typescript Discord.js选项类型

dfuffjeb  于 2022-12-14  发布在  TypeScript
关注(0)|答案(1)|浏览(103)

我遇到了一点麻烦,试图找出哪些选项类型的工作除了字符串。
我代码:

const { Client, CommandInteraction } = require("discord.js");

module.exports = {
    name: "test",
    description: "mention a user",
    type: 'CHAT_INPUT',
    options: [
        {
            name: 'user',
            description: 'mentions a user',
            type: 'User',
            required: 'true'
        }
    ],
    /**
     *
     * @param {Client} client
     * @param {CommandInteraction} interaction
     * @param {String[]} args
     */
    run: async (client, interaction, args) => {
        interaction.followUp('yes');
    },
};

运行后,我收到一个长错误,消息为:不一致API错误:无效的窗体正文3。选项[0]:字段“type”是确定模型类型所必需的。我知道这与我的处理程序无关,因为其他一切都运行得很好。

gab6jxml

gab6jxml1#

您应该使用type等于6。如Discord文档中所述,选项类型应该是数字。

SUB_COMMAND 1   
SUB_COMMAND_GROUP 2 
STRING 3    
INTEGER 4
BOOLEAN 5   
USER 6  
CHANNEL 7
ROLE 8  
MENTIONABLE 9
NUMBER 10
ATTACHMENT 11

使用您的代码实现:

const { Client, CommandInteraction } = require("discord.js");

module.exports = {
    name: "test",
    description: "mention a user",
    type: 'CHAT_INPUT',
    options: [
        {
            name: 'user',
            description: 'mentions a user',
            type: 6,
            required: 'true'
        }
    ],
    /**
     *
     * @param {Client} client
     * @param {CommandInteraction} interaction
     * @param {String[]} args
     */
    run: async (client, interaction, args) => {
        interaction.followUp('yes');
    },
};

相关问题