[英]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.
这段代码过去一直有效,但现在由于某种原因,获取的日志没有针对其固定触发了 messageUpdate 事件的消息的条目。
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 ).从 v13 开始,id 属性的命名已更改(如指南中所示)。 Instead of
.xxxID
, it's now .xxxId
而不是
.xxxID
,现在是.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还要注意,
.find()
更适合这个,因为它得到第一个 object 匹配回调
const pinLog = fetchedLogs.entries.find(f => f.extra.messageId == oldMessage.id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.