繁体   English   中英

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

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

所以我试图让我的机器人记录消息固定和取消固定。 这段代码过去一直有效,但现在由于某种原因,获取的日志没有针对其固定触发了 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;

显示的错误是:

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

这个确切的代码直到最近才有效。

我尝试过的事情:

  1. 在获取日志之前尝试让代码休眠一段时间(最多 10 秒)。 不工作
  2. 试图将提取放入循环中,直到 pinLog 不再是未定义的。 导致死循环。

从 v13 开始,id 属性的命名已更改(如指南中所示)。 而不是.xxxID ,现在是.xxxId

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

还要注意, .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