2 回答
TA贡献1891条经验 获得超3个赞
我找到了!经过一些测试,我发现当频道更新时,会发生以下四种情况之一。
如果用户加入则
oldState.channelID
返回null如果用户返回
newState.channelID
null如果用户将自己静音或被震聋,则
oldState.channelID
等于newState.channelID
如果用户移动的频道
oldState.channelID
不等于newState.channelID
我Discord.Client()
的设置为client
,所以如果你的不同,请更改
client.on('voiceStateUpdate', (oldState, newState) => {
if(oldState.channelID === newState.channelID) {
console.log('a user has not moved!')
}
if(oldState.channelID != null && newState.channelID != null && newState.channelID != oldState.channelID) {
console.log('a user switched channels')
}
if(oldState.channelID === null) {
console.log('a user joined!')
}
if (newState.channelID === null) {
console.log('a user left!')
}
});
TA贡献1856条经验 获得超17个赞
尝试这个片段,请让我知道它对你有什么作用。
let oldChannel = oldState.voiceChannel;
let newChannel = newState.voiceChannel;
if(oldChannel === undefined && newChannel !== undefined) {
// User has joined a channel
} else if(newChannel === undefined) {
// User has left a channel
}
添加回答
举报