如何检测用户何时加入语音频道?

bla*_*ing 4 discord discord.js

我目前正在尝试为我的服务器创建一个机器人,我想做的一件事是让它检测用户何时加入任何语音频道并简单地让它发送消息。我个人无法弄清楚它或在互联网上找到任何答案,因为大多数时候人们都是根据命令来检测它,而我希望它是被动的。我知道 voiceStateUpdate 已更改,并且有些内容与我过去看到的其他人使用它的方式有所不同。

如果有人有任何解决方案请告诉我,谢谢。

sta*_*ers 7


    client.on('voiceStateUpdate', (oldState, newState) => {
        if (newState.channelID === null) console.log('user left channel', oldState.channelID);
        else if (oldState.channelID === null) console.log('user joined channel', newState.channelID);
        else console.log('user moved channels', oldState.channelID, newState.channelID);
    });

Run Code Online (Sandbox Code Playgroud)