机器人被踢出语音通道事件



我试图为我的音乐机器人做的是让他在被踢出语音频道时报告,例如说"我被强行断开了连接";。我没有找到一个有用的属性或方法来检查这个,所以我向一些朋友寻求帮助,并尝试了这个:

client.on('voiceStateUpdate', (oldMember, newMember) => {
let newUserChannel = newMember.voiceChannel
if (newUserChannel === undefined) return console.log("I was kicked from the voice channel")
})

它不起作用。

那么,有什么办法解决我的问题吗?

我不久前也遇到了同样的问题。这是我用来解决它的方法:

Client.on('voiceStateUpdate', (oldState, newState) => {

// Represents a mute/deafen update
if(oldState.channelId === newState.chanelId) return console.log('Mute/Deafen Update');
// Some connection
if(!oldState.channelId && newState.channelId) return console.log('Connection Update');
// Disconnection
if(oldState.channelId && !newState.channelId){
console.log('Disconnection Update');
// Bot was disconnected?
if(newState.id === Client.user.id) return console.log(`${Client.user.username} was disconnected!`);
}
});

由于voiceStateUpdate事件在与语音频道相关的所有内容中都会触发,因此您应该添加尽可能多的场景,以使事情按预期进行。

最新更新