简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM