进入房间后扔到另一个房间

当有人走进一个房间时,我希望他们把它扔到另一个房间


这是代码


client.on("voiceStateUpdate", function(oldMember, newMember){


let room = client.channels.cache.get('586962325240676370');

let newVoice = newMember.voice.channelID

     

if (newVoice == room){

let channelgit = client.channels.cache.get('757403475129794600')    

member.voice.setChannel(channelgit);

    }

});

我收到这个错误


C:\Users\user\Desktop\proton mdul\index.js:44

     let newVoice = newMember.voice.channelID

                                    ^


TypeError: Cannot read property 'channelID' of undefined

    at Client.<anonymous> (C:\Users\user\Desktop\proton mdul\index.js:44:37)

    at Client.emit (events.js:311:20)

    at VoiceStateUpdate.handle (C:\Users\user\Desktop\proton mdul\node_modules\discord.js\src\client\actions\VoiceStateUpdate.js:40:14)

    at Object.module.exports [as VOICE_STATE_UPDATE] (C:\Users\user\Desktop\proton mdul\node_modules\discord.js\src\client\websocket\handlers\VOICE_STATE_UPDATE.js:4:35)

    at WebSocketManager.handlePacket (C:\Users\user\Desktop\proton mdul\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)

    at WebSocketShard.onPacket (C:\Users\user\Desktop\proton mdul\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)

    at WebSocketShard.onMessage (C:\Users\user\Desktop\proton mdul\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)

    at WebSocket.onMessage (C:\Users\user\Desktop\proton mdul\node_modules\ws\lib\event-target.js:125:16)

    at WebSocket.emit (events.js:311:20)

    at Receiver.receiverOnMessage (C:\Users\user\Desktop\proton mdul\node_modules\ws\lib\websocket.js:797:20)


慕的地8271018
浏览 105回答 1
1回答

子衿沉夜

该voiceStateUpdate事件实际上返回oldState,并且newState在最新版本的discord.js(source)中,它们都是VoiceState对象,而不是GuildMember对象。因此,您必须更改代码才能使用VoiceState。这非常简单,因为您可以通过获取属性来GuildMember从 a获取对象。VoiceState.member另一件事是,newState有时可能是因为当有人离开语音频道undefined时该事件也会触发。这意味着您还必须检查该值是否未定义。如果您要实现所有这些更改,它将如下所示:client.on("voiceStateUpdate", function(oldState, newState) {&nbsp; &nbsp; if (newState === undefined) {&nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; }&nbsp; &nbsp; let room = client.channels.cache.get('586962325240676370');&nbsp; &nbsp; let voiceChannelID = newState.channelID;&nbsp; &nbsp; if (voiceChannelID === room) {&nbsp; &nbsp; &nbsp; &nbsp; let channelgit = client.channels.cache.get('757403475129794600');&nbsp; &nbsp; &nbsp; &nbsp; newState.setChannel(channelgit);&nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript