为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕的地8271018 2023-07-14 15:44:52
当有人走进一个房间时,我希望他们把它扔到另一个房间这是代码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)
查看完整描述

1 回答

?
子衿沉夜

TA贡献1828条经验 获得超3个赞

该voiceStateUpdate事件实际上返回oldState,并且newState在最新版本的discord.js(source)中,它们都是VoiceState对象,而不是GuildMember对象。


因此,您必须更改代码才能使用VoiceState。这非常简单,因为您可以通过获取属性来GuildMember从 a获取对象。VoiceState.member


另一件事是,newState有时可能是因为当有人离开语音频道undefined时该事件也会触发。这意味着您还必须检查该值是否未定义。


如果您要实现所有这些更改,它将如下所示:


client.on("voiceStateUpdate", function(oldState, newState) {

    if (newState === undefined) {

        return;

    }


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

    let voiceChannelID = newState.channelID;


    if (voiceChannelID === room) {

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

        newState.setChannel(channelgit);

    }

});


查看完整回答
反对 回复 2023-07-14
  • 1 回答
  • 0 关注
  • 104 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信