如何在 Discord.js 中发送临时消息

Jay*_*cks 1 discord.js

让discord.js机器人在用户使用斜杠命令时发送临时消息,我尝试过使用interation.editReply({content: "etc-etc", ephemeral:true});,以及任何看起来合理但似乎不成功的东西,请发送一个示例,我将如何实现临时消息!

编辑:

我的斜杠命令帮助文件:

const { Message, Client } = require("discord.js");

module.exports = {
    name: "help",
    description: "Sends web page url for all commands",
    run: async (client, interaction) => {

        await interaction.deferReply({ephemeral: true});

        interaction.editReply({
            embeds: [
                {
                    title: `${client.user.username}'s Help Page`,
                    description: `https://help.tcb.jayeshrocks.xyz`,
                    color: "RANDOM"
                }
            ]
        })
    }
};
Run Code Online (Sandbox Code Playgroud)

现在我收到交互已回复错误

编辑2:这是我的interactionCreate.js 的一个错误,现在我修复了它,它正在与 .deferReply() 一起使用,谢谢!

Tur*_*paw 5

根据文档,您需要ephemeralInteractionReplyOptions. 您还可以查看 Discord.js关于临时响应的指南

您可能并不总是希望有权访问该频道的每个人都看到斜杠命令的响应。值得庆幸的是,Discord 实现了一种对除了斜杠命令执行者之外的所有人隐藏消息的方法。这种类型的消息称为ephemeral消息,可以通过ephemeral: trueInteractionReplyOptions

Discordjs. 指南

这是一个例子:

//use the `interaction.reply()` function normally

await interaction.reply({
   embeds: [{
      title: `${client.user.username}'s Help Page`,
      description: `https://help.tcb.jayeshrocks.xyz`,
      color: "RANDOM"
   }],
   //this is the important part
   ephemeral: true
});
Run Code Online (Sandbox Code Playgroud)

短暂延迟回复:

您也可以在执行时使用该ephemeral选项deferReply()

//use the `interaction.deferReply()` function normally

await interaction.deferReply({
   //this is the important part
   ephemeral: true
});
Run Code Online (Sandbox Code Playgroud)

了解更多