首页 > 解决方案 > 如何让我的不和谐机器人删除它自己之前发送的消息?

问题描述

目前,我的机器人中有一个命令,它将对discord.gg消息中的任何内容做出反应。我希望机器人能够在每次发布不和谐邀请时发布嵌入消息,但删除它发送的最后一条嵌入消息,这样看起来机器人在频道末尾保留一条特定消息。

这就是代码现在的样子,感谢您的帮助!

let keyword15 = ["discord.gg"];
if (msg.author.bot) return;
if((msg.content.toLowerCase().includes(keyword15) )
){          
    const embed2 = new Discord.MessageEmbed()
    .setDescription('Promotion Operator \n ▫️ **Do not post outside the advertisement channel.** \n ▫️ **Do not advertise your server via DM.**')
    .setColor(0x000000)
    msg.channel.send(embed2);    
}

标签: discorddiscord.js

解决方案


我不知道如何删除最后一个嵌入,但是我想出了另一个你可以尝试的解决方案。

let keyword15 = ["discord.gg"];
if (msg.author.bot) return;
if((msg.content.toLowerCase().includes(keyword15) )
){          
    const embed2 = new Discord.MessageEmbed()
    .setDescription('Promotion Operator \n ▫️ **Do not post outside the advertisement channel.** \n ▫️ **Do not advertise your server via DM.**')
    .setColor(0x000000)
    msg.channel.send(embed2).then(msg => {
msg.delete(300000)
});
}

将在 5 分钟后删除嵌入,您可以随时更改时间,请记住不和谐使用毫秒,因此如果您想使用 10 分钟,则必须输入 600000 等。


推荐阅读