我一直在试图找到一个解决办法,我可以如何访问一个特定的不和谐。特定索引处的js审核日志。这是我的意思的一个例子:
fetchedLogs = await message.guild.fetchAuditLogs({
//"message" refers to the message that the client received
limit: 10,
type: MEMBER_BAN_ADD
});
这是一个将执行者、目标以及fetchedLogs
中每个日志的日志原因记录到控制台的函数。
function logFilter(l){
for (i = 0; i < 10; i++){
const { executor, target, reason } = e.entries[i]
const logResult = `Executor: ${executor}\n Target: ${target}\n Reason: ${reason}`
console.log(logResult)
}
}
logFilter(fetchedLogs)
这是运行后的错误:
const { executor, target, reason } = l.entries[i]
^
TypeError: Cannot destructure property 'executor' of 'l.entries[i]' as it is undefined.
基本上,我遇到的问题是我无法参考具体的审计日志。这可以被证明,因为当我运行这个而不是const{执行器,目标,原因}=l.entries[i]时,它不会输出错误:
const { executor, target, reason } = l.entries.first()
感谢您的帮助。谢谢
这是因为它是一个集合。您可以使用集合#at()来解决这个问题:
const { executor, target, reason } = l.entries.at(i)