discord.js Editting Slash Command Interaction Messages(discord.js编辑劈开命令交互消息)
本文介绍了discord.js编辑劈开命令交互消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我在下面的代码中使用discord.js:
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: "Getting Data..."
}
}
})
我希望以后能够编辑此邮件,但我看到的所有内容都需要邮件ID,而我似乎无法从此代码中获取邮件ID。
推荐答案
您可以使用此补丁请求编辑交互响应(请参阅: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(一个优点是这样不会出现编辑过的&q;。)
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 5,
},
})
这篇关于discord.js编辑劈开命令交互消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:discord.js编辑劈开命令交互消息


猜你喜欢
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01