Discord Slash 命令:发送嵌入时出错

Aki*_*kio 1 javascript node.js discord discord.js

我正在为我的机器人创建一个斜杠命令。所以我尝试了这个

Client.ws.on('INTERACTION_CREATE', async interaction => {
    Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
        type: 4,
        data: {
            content: 'hello world!'
        }
    }})
})
Run Code Online (Sandbox Code Playgroud)

这很好用。
所以我尝试发送嵌入并尝试下面的这些(2)代码

Client.ws.on('INTERACTION_CREATE', async interaction => {
    Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
        type: 4,
        data: {
            content: {
                embed: exampleEmbed
            }
        }
    }})
})
Run Code Online (Sandbox Code Playgroud)

Client.ws.on('INTERACTION_CREATE', async interaction => {
    Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
        type: 4,
        data: {
            embed: exampleEmbed
        }
    }})
})
Run Code Online (Sandbox Code Playgroud)

这些都不起作用。

那么我做错了什么?
或者,如何使用斜杠命令发送嵌入?

编辑:这就是我的定义exampleEmbed

const exampleEmbed = {
    color: 0x0099ff,
    title: 'Hello world',
    thumbnail: {
        url: 'https://i.imgur.com/wSTFkRM.png',
    },
    image: {
        url: 'https://i.imgur.com/wSTFkRM.png',
    }
};
Run Code Online (Sandbox Code Playgroud)

小智 6

对于使用discord.js API 的任何人,我使用:

    const embed = new MessageEmbed().setTitle('testing');

    const messageId = await interaction.reply({ embeds: [ embed ] });
Run Code Online (Sandbox Code Playgroud)


Pig*_*lex 5

它接受嵌入数组,称为embeds属性。

Client.ws.on('INTERACTION_CREATE', async interaction => {
    Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
        type: 4,
        data: {
            embeds: [ exampleEmbed ]
        }
    }})
})
Run Code Online (Sandbox Code Playgroud)

来自https://discord.com/developers/docs/interactions/slash-commands#responding-to-an-interaction