提问者:小点点

Discord斜杠命令:发送嵌入时出错


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

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

这工作得很好。
所以我尝试用它发送一个嵌入,并尝试下面的(2)个代码

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

而且

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

但这些都没用。

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

编辑:这是我定义exampleembed的方式

const exampleEmbed = {
    color: 0x0099ff,
    title: 'Hello world',
    thumbnail: {
        url: 'https://i.imgur.com/wSTFkRM.png',
    },
    image: {
        url: 'https://i.imgur.com/wSTFkRM.png',
    }
};

共1个答案

匿名用户

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

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

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