忽略漫游器删除的消息

时间:2019-11-29 16:49:59

标签: javascript discord.js

因此,我正在处理已删除的消息日志。我可以使用它,但是该机器人删除的消息也已记录下来。而不是1次。我收到了5条相同的已删除邮件。我已经尝试过类似if(!messageDelete.author.bot) {}的方法,但是尝试后仍会记录僵尸程序删除的消息并仍然创建10条消息。这是我当前正在使用的代码:

bot.on("messageDelete", (messageDelete) => {
  if(!messageDelete.author.bot) {
    let DeleteEmbed = new Discord.RichEmbed()
    .setTitle("**DELETED MESSAGE OWO**")
    .setColor("#ed0c75")
    .addField("Author", messageDelete.author.tag, true)
    .addField("Channel", messageDelete.channel, true)
    .addField("Message", messageDelete.content)
    .setFooter(`Message ID: ${messageDelete.id} | Author ID: ${messageDelete.author.id}`, messageDelete.author.displayAvatar);

    let DeleteChannel = messageDelete.guild.channels.find(x => x.name === "mod-logs");
    DeleteChannel.send(DeleteEmbed);
}})

,这是输出的屏幕截图。例如,如果我使用 purge 命令,它将记录所有已删除的消息。

screenshot

我希望有人可以帮助我。

2 个答案:

答案 0 :(得分:1)

为此,您需要查看Discord中的audit logs,审核日志同时显示了执行者和受害者(我不知道该怎么称呼)。

要查看已删除的邮件审核日志,请使用:

let logs = await messageDelete.guild.fetchAuditLogs({
        type: 72
    });

然后查看最新的内容:

let entry = logs.entries.first();

然后检查该漫游器是否删除了一条消息以及该怎么做(如果没有删除):

if (entry.executor.username === bot.user.username) {
        return;
    } else {
        let DeleteEmbed = new Discord.RichEmbed()
    .setTitle("**DELETED MESSAGE OWO**")
    .setColor("#ed0c75")
    .addField("Author", messageDelete.author.tag, true)
    .addField("Channel", messageDelete.channel, true)
    .addField("Message", messageDelete.content)
    .setFooter(`Message ID: ${messageDelete.id} | Author ID: ${messageDelete.author.id}`, messageDelete.author.displayAvatar);

    let DeleteChannel = messageDelete.guild.channels.find(x => x.name === "mod-logs");
    DeleteChannel.send(DeleteEmbed);
    };

所有这些代码在一起看起来像这样:

let logs = await messageDelete.guild.fetchAuditLogs({
        type: 72
    });
let entry = logs.entries.first();
if (entry.executor.username === bot.user.username) {
        return;
    } else {
        let DeleteEmbed = new Discord.RichEmbed()
    .setTitle("**DELETED MESSAGE OWO**")
    .setColor("#ed0c75")
    .addField("Author", messageDelete.author.tag, true)
    .addField("Channel", messageDelete.channel, true)
    .addField("Message", messageDelete.content)
    .setFooter(`Message ID: ${messageDelete.id} | Author ID: ${messageDelete.author.id}`, messageDelete.author.displayAvatar);

    let DeleteChannel = messageDelete.guild.channels.find(x => x.name === "mod-logs");
    DeleteChannel.send(DeleteEmbed);
    };

我希望这有助于回答您的问题!

P.S-好的机器人名称。

答案 1 :(得分:0)

也许您可以尝试将!messageDelete.author.bot替换为message.author != bot.user