您可以使用此补丁请求编辑交互响应(请参阅:Followup Messages):
PATCH /webhooks/<application_id>/<interaction_token>/messages/@original
使用axios library的基本示例:
axios.patch(`https://discord.com/api/v8/webhooks/${appId}/${interaction.token}/messages/@original`, { content: 'New content' });
此请求的答案也将包含 message-id。
这是一个示例函数,它将以纯文本或嵌入对象的形式编辑原始消息,并返回不和谐的消息对象以供进一步使用(例如添加回复表情符号等):
const editInteraction = async (client, interaction, response) => {
// Set the data as embed if reponse is an embed object else as content
const data = typeof response === 'object' ? { embeds: [ response ] } : { content: response };
// Get the channel object by channel id:
const channel = await client.channels.resolve(interaction.channel_id);
// Edit the original interaction response:
return axios
.patch(`https://discord.com/api/v8/webhooks/${appId}/${interaction.token}/messages/@original`, data)
.then((answer) => {
// Return the message object:
return channel.messages.fetch(answer.data.id)
})
};
除了发送诸如“正在获取数据...”之类的初始消息之外,您还可以发送类型 5 的空响应。这是内置方法,也会显示一些加载动画:) See here (One优点是这种方式不会出现“已编辑”。)
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 5,
},
})