简体   繁体   English

尝试获取 discord.js 上的消息固定审核日志不会返回最近固定消息的日志

[英]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:我尝试过的事情:

  1. Attempted to make the code sleep for a bit (up to 10 seconds) before fetching the logs.在获取日志之前尝试让代码休眠一段时间(最多 10 秒)。 Did not work不工作
  2. Attempted to put the fetch into a loop until pinLog is not undefined anymore.试图将提取放入循环中,直到 pinLog 不再是未定义的。 Resulted in an infinite loop.导致死循环。

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.

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