discord.js编辑劈开命令交互消息 [英] discord.js Editting Slash Command Interaction Messages

查看:35
本文介绍了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编辑劈开命令交互消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆