簡體   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