javascript - 我可以通过哪个事件查看“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);
});
我的问题是,当每个用户离开房间时,最新的日志控制台都会丢失。即使该人没有断开连接。
解决方案
您没有使用正确形式的代码。
您需要通过老会员和新会员要求语音更新!
当有人从(旧)语音通道(状态)断开连接时,旧成员正在使用。
为了显示您断开连接的成员,您必须使用:
(`${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}.`);
}
});
推荐阅读
- react-native - React Native 的核心框架如何部署到应用程序使用的设备上?
- r - 使用 ggplot2 构建箱线图
- angular - 需要使用 Angular 5 服务警告用户页面到期的解决方案吗?
- javascript - 使用 window.location.replace 后如何防止页面刷新
- java - 如何减少 Java 中的振幅数组大小?
- postgresql - 哪些命令不能在事务块中执行?
- python - 如何使用 python discord 向机器人所在的每个服务器发送消息
- python - 无法向 Gmail 验证 Google 服务帐户
- firebase - 使用 Firebase 云功能向非谷歌服务发送 POST 请求
- c# - EditorFor 和 ApplyFormatInEditMode