Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在执行命令并移动到node.js中的其他语音频道后,如何检查此人的语音频道ID?_Javascript_Node.js_Discord_Discord.js - Fatal编程技术网

Javascript 在执行命令并移动到node.js中的其他语音频道后,如何检查此人的语音频道ID?

Javascript 在执行命令并移动到node.js中的其他语音频道后,如何检查此人的语音频道ID?,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,在执行命令后,我需要检查此人所在的语音频道ID。如果它在这个频道上,我希望机器人移动到另一个想要的频道 var idchannel = member.get.voiceChannelID; if(idchannel === "ID"){ //command // and i need to move this user to another channel. } else { message.reply("You are

在执行命令后,我需要检查此人所在的语音频道ID。如果它在这个频道上,我希望机器人移动到另一个想要的频道

      var idchannel = member.get.voiceChannelID;
      if(idchannel === "ID"){
      //command
      // and i need to move this user to another channel.
    }
    else {
      message.reply("You are not on the correct Channel.");
    }
编辑:

从Discord.js v12开始,由于语音相关功能的更改,我的原始答案将不再有效

假设您有
成员
,则可以使用访问与语音相关的选项。这样,您就可以引用属性来访问所连接的成员的ID(若有)。把它放在一起,就是
member.voice.channelID

至于将成员移动到特定频道,您可以使用方法so
member.voice.setChannel(…)

更新后的代码如下所示:

const voiceChannelID=member.voice.channelID;
如果(voiceChannelID===‘某些频道ID’){
member.voice.setChannel('target channel ID')//您可能需要等待,需要异步fn
.catch(控制台错误);
}否则{
message.reply('您的频道不正确')//请参阅最后一条评论
.catch(控制台错误);
}

原版(v11):

您可以参考用户使用的连接到的语音频道。然后根据预期ID检查通道的属性

要将成员从一个语音频道移动到另一个语音频道,可以使用以下方法

const voiceChannel=message.member.voiceChannel;//请记住,如果
//它们没有连接到任何通道。
if(voiceChannel&&voiceChannel.id==“频道id”){
message.member.setVoiceChannel(/*其他一些频道或ID*/);
}回复(“您的频道不正确。”);
确保从你的承诺中发现任何错误。请参阅。

编辑:

从Discord.js v12开始,由于语音相关功能的更改,我的原始答案将不再有效

假设您有
成员
,则可以使用访问与语音相关的选项。这样,您就可以引用属性来访问所连接的成员的ID(若有)。把它放在一起,就是
member.voice.channelID

至于将成员移动到特定频道,您可以使用方法so
member.voice.setChannel(…)

更新后的代码如下所示:

const voiceChannelID=member.voice.channelID;
如果(voiceChannelID===‘某些频道ID’){
member.voice.setChannel('target channel ID')//您可能需要等待,需要异步fn
.catch(控制台错误);
}否则{
message.reply('您的频道不正确')//请参阅最后一条评论
.catch(控制台错误);
}

原版(v11):

您可以参考用户使用的连接到的语音频道。然后根据预期ID检查通道的属性

要将成员从一个语音频道移动到另一个语音频道,可以使用以下方法

const voiceChannel=message.member.voiceChannel;//请记住,如果
//它们没有连接到任何通道。
if(voiceChannel&&voiceChannel.id==“频道id”){
message.member.setVoiceChannel(/*其他一些频道或ID*/);
}回复(“您的频道不正确。”);

确保从你的承诺中发现任何错误。请参阅。

谢谢。您知道如何将该频道中的任何人移动到其他频道吗?@Johnyttw移动用户或移动客户端/机器人?将用户移动到其他频道channel@Johnyttw我已经编辑了答案来演示如何操作。现在是
message.member.voice.channel
now(discord.jsv12)。谢谢。您知道如何将该频道中的任何人移动到其他频道吗?@Johnyttw移动用户或移动客户端/机器人?将用户移动到其他频道channel@Johnyttw我对答案进行了编辑,以说明如何操作。现在是
message.member.voice.channel
now(discord.jsv12)。