I have been trying to find a solution on how I can access a specific discord.js audit log at a specific index. This is an example of what I mean:
fetchedLogs = await message.guild.fetchAuditLogs({
//"message" refers to the message that the client received
limit: 10,
type: MEMBER_BAN_ADD
});
This is a function to log the executor, target and the reason of the log of each of the logs in fetchedLogs to the console.
function logFilter(l){
for (i = 0; i < 10; i++){
const { executor, target, reason } = e.entries[i]
const logResult = `Executor: ${executor}\n Target: ${target}\n Reason: ${reason}`
console.log(logResult)
}
}
logFilter(fetchedLogs)
This is the error after it was ran:
const { executor, target, reason } = l.entries[i]
^
TypeError: Cannot destructure property 'executor' of 'l.entries[i]' as it is undefined.
Basically, the problem I ran into is that I am unable to refer to the specific audit log. This can be proven because when I run this instead of const { executor, target, reason } = l.entries[i] , it doesn't output an error:
const { executor, target, reason } = l.entries.first()
Any help is appreciated. Thanks
That's because it's a Collection. You can use Collection#at() to fix that:
const { executor, target, reason } = l.entries.at(i)