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

168
Views
Attempting to get message pin audit logs on discord.js does not return the log for the most recently pinned message

So I am trying to get my bot to log message pins and unpins. This code used to work until recently but now for some reason, the fetched logs do not have an entry for the message whose pinning triggered the messageUpdate event.

const fetchedLogs = await oldMessage.guild.fetchAuditLogs({
      type: 'MESSAGE_PIN',
    });
const pinLog = fetchedLogs.entries.filter(f => f.extra.messageID == oldMessage.id).first();
const { executor } = pinLog;

The error shown is:

Uncaught Promise Rejection TypeError: Cannot destructure property 'executor' of 'pinLog' as it is undefined.

This exact code used to work until recently.

Things I have tried:

  1. Attempted to make the code sleep for a bit (up to 10 seconds) before fetching the logs. Did not work
  2. Attempted to put the fetch into a loop until pinLog is not undefined anymore. Resulted in an infinite loop.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As of v13, the naming for id properties have been changed (as shown in guide). Instead of .xxxID, it's now .xxxId

// messageID -> messageId
const pinLog = fetchedLogs.entries.filter(f => f.extra.messageId == oldMessage.id).first()

Also note, .find() would be more suited for this, since it gets the first object matching the callback

const pinLog = fetchedLogs.entries.find(f => f.extra.messageId == oldMessage.id)
about 4 years ago · Juan Pablo Isaza 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!