[英]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.
這個確切的代碼直到最近才有效。
我嘗試過的事情:
從 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.