首页 > 解决方案 > 我可以通过哪个事件查看“MEMBER_DISCONNECT”审核日志?

问题描述

这是代码:

client.on("voiceStateUpdate", async function(oldMember, newMember){

const guild = client.guilds.cache.get("586962324544553011");
const entry = await guild.fetchAuditLogs({type: 'MEMBER_DISCONNECT'}).then(audit => audit.entries.first())

console.log(entry);
    
});

我的问题是,当每个用户离开房间时,最新的日志控制台都会丢失。即使该人没有断开连接。

标签: javascriptdiscord.js

解决方案


您没有使用正确形式的代码。

您需要通过老会员和新会员要求语音更新!

当有人从(旧)语音通道(状态)断开连接时,旧成员正在使用。

为了显示您断开连接的成员,您必须使用:

(`${oldVoiceState.member} disconnected from ${oldVoiceState.channel.name}.`);

所以正确的方法是先询问“已连接”的成员,然后再询问“未连接”的成员:

你可以试试这个:

client.on('voiceStateUpdate', (oldVoiceState, newVoiceState) => {
    if (newVoiceState.channel) {
    console.log(`${newVoiceState.member} connected to ${newVoiceState.channel.name}.`);
        
    } else if (oldVoiceState.channel) {
    console.log(`${oldVoiceState.member} disconnected from ${oldVoiceState.channel.name}.`);
        
    }
});

推荐阅读