我正在为我的机器人创建一个斜杠命令。所以我尝试了这个
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',
}
};
答案 0 :(得分:2)
它接受一个嵌入数组,称为 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#responding-to-an-interaction
答案 1 :(得分:1)
我认为您需要使用 embeds
属性将 embeds 作为数组发送到 data
内,但根据文档 “目前并非所有消息字段都受支持.”
Client.ws.on('INTERACTION_CREATE', async interaction => {
Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
type: 4,
data: {
content: 'hello world!',
embeds: [exampleEmbed]
}
}})
})
答案 2 :(得分:0)
对于使用 discord.js 嵌入的任何人,您必须在嵌入上设置 type
属性!否则你会得到一个错误 400。
import { MessageEmbed } from 'discord.js'
const exampleEmbed = new MessageEmbed({
title: 'Error occurred',
description: description,
type: 'rich',
});
Client.ws.on('INTERACTION_CREATE', async interaction => {
Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
type: 4,
data: {
embeds: [exampleEmbed]
}
}})
})