Catch deleted messages with Events.GuildAuditLogEntryCreate

Hi, I have problem with this code. As you can see on video it logs only one random message when it wants and when rest of the messages are deleted it doesn't work.
bot.on(Events.GuildAuditLogEntryCreate, async auditLog => {

console.log("Delete check")

const { action, extra: channel, executorId, targetId } = auditLog;

if ( action !== AuditLogEvent.MessageDelete ) return;

const executor = await bot.users.fetch(executorId);

const target = await bot.users.fetch(targetId);

console.log(`A message by ${target.tag} was deleted by ${executor.tag} in ${channel}.`);
});
bot.on(Events.GuildAuditLogEntryCreate, async auditLog => {

console.log("Delete check")

const { action, extra: channel, executorId, targetId } = auditLog;

if ( action !== AuditLogEvent.MessageDelete ) return;

const executor = await bot.users.fetch(executorId);

const target = await bot.users.fetch(targetId);

console.log(`A message by ${target.tag} was deleted by ${executor.tag} in ${channel}.`);
});
7 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
space
space11mo ago
!"Unkown
!"Unkown11mo ago
its normal messageDelete logs get stacked so when u delete one message after 10min i think u get the log and then if u delete another the log gonna be edited User deleted 2 messages in channel
shaxu
shaxu11mo ago
That seems to be the problem, do u know how I would make it work so i get only last message from this stack? I just want to log every deleted message.
!"Unkown
!"Unkown11mo ago
u can use the event messageDelete but the author will not be right or u can cache the logs and then when a message is deleted check whats logs is different from before
shaxu
shaxu11mo ago
Thanks a lot
!"Unkown
!"Unkown11mo ago
np