Javascript 如何将用户重定向到其他频道?

Javascript 如何将用户重定向到其他频道?,javascript,discord,discord.js,bots,Javascript,Discord,Discord.js,Bots,我希望我的机器人在用户尝试加入任何其他频道时将其移动到指定的语音频道 据我所知: client.on('voiceStateUpdate',(oldMember,newMember)=>console.log(oldMember)); 已替换为: client.on('voiceStateUpdate',(oldState,newState)=>console.log(oldState)); 那么如何返回加入语音频道的用户呢?您可以使用VoiceState的member属性获取加入Voice

我希望我的机器人在用户尝试加入任何其他频道时将其移动到指定的语音频道

据我所知:

client.on('voiceStateUpdate',(oldMember,newMember)=>console.log(oldMember));
已替换为:

client.on('voiceStateUpdate',(oldState,newState)=>console.log(oldState));

那么如何返回加入语音频道的用户呢?

您可以使用
VoiceState
member
属性获取加入
VoiceChannel
的用户

client.on(“voiceStateUpdate”(旧状态,新状态)=>{
const Channel=client.channels.cache.get(“ChannelID”);//希望用户移入的通道。
if(!Channel)返回console.error(“无效通道”);//确保通道存在。
如果(!newState.channel)返回false;//用户已断开与频道的连接。
if(newState.channelID!==Channel.id){//检查用户是否在想要的频道中。
newState.member.voice.setChannel(Channel.catch(error=>console.error(error));//将用户移动到所需的频道。
};
});
我真的建议您拒绝加入频道的权限,而不是这样做