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:
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.