Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
How to access specific discord.js audit logs with an index

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

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

That's because it's a Collection. You can use Collection#at() to fix that:

const { executor, target, reason } = l.entries.at(i)
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!