2 回答

TA貢獻1891條經(jīng)驗 獲得超3個贊
我找到了!經(jīng)過一些測試,我發(fā)現(xiàn)當頻道更新時,會發(fā)生以下四種情況之一。
如果用戶加入則
oldState.channelID
返回null如果用戶返回
newState.channelID
null如果用戶將自己靜音或被震聾,則
oldState.channelID
等于newState.channelID
如果用戶移動的頻道
oldState.channelID
不等于newState.channelID
我Discord.Client()
的設(shè)置為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條經(jīng)驗 獲得超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
}
添加回答
舉報