I’m trying to make a small Logger Discord Bot. The code below is how i get the audit logs entry (for the channelDelete event).
But i got a big problem: also if the user who deletes the message (user A) is not a bot or the author of the message (user B), the executor (and also the target) is not correct, it’s referred to a previous deleted message (the channel
data is about the right deleted channel).
Example: user A create a message -> User B deletes it.
Then user B creates a message -> User A deletes it.
Both logs have as executor user B and target User A (waited until the end of an action before to perform an other)
I’ve also ried to add a setTimeout(() => {...}, 2500);
But nothing changes, it doesn’t give the right executor (and target).
What i’m doing wrong?
const AuditLogFetch = await channel.guild.fetchAuditLogs({
limit: 1,
type: auditType,
});
if (!AuditLogFetch.entries.first())
return console.error(`No entries found.`);
const entry = AuditLogFetch.entries.first();
let parentChannel = null;
if (entry.channelParentId)
parentChannel = channel.guild.channels.cache.get(channel.parentId).toString();
const chDeleteEmbed = {
color: colors.DARK_RED,
author: {
name: `${entry.globalName != null ? entry.globalName : 'No nickname'} [${entry.username != null ? entry.username : 'No username'}]`,
icon_url: entry.displayAvatarURL()
},
description: `${channel.type} deleted by <@${entry.executor.id}> n
${parentChannel != null ? `In category: ${parentChannel}` : '' }`,
fields: [
{
name: 'Nome canale',
value: `${channel.name}`
}
],
}
// send embed func ...
})
Thank you