[英]how can i check the voice channel ID that the person is after they execute a command and move to other voice channel in node.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 not on the correct Channel.");
}
编辑:
从 Discord.js v12 开始,由于语音相关功能的变化,我的原始答案将不再有效。
假设您有GuildMember member
,您可以使用member.voice
访问与语音相关的选项。 通过该VoiceState ,您可以参考VoiceState#channelID
属性来访问成员连接到的VoiceChannel的 ID(如果有)。 放在一起,就是member.voice.channelID
。
至于将成员移动到特定频道,您可以使用VoiceState#setChannel()
方法,因此member.voice.setChannel(...)
。
更新后的代码如下所示:
const voiceChannelID = member.voice.channelID;
if (voiceChannelID === 'some channel ID') {
member.voice.setChannel('target channel ID') // you may want to await this, async fn required
.catch(console.error);
} else {
message.reply('You are not in the correct channel.') // see last comment
.catch(console.error);
}
原始(v11):
您可以使用GuildMember.voiceChannel
用户连接到的语音通道。 然后根据预期的 ID 检查频道的id
属性。
要将成员从一个语音通道移动到另一个,您可以使用GuildMember.setVoiceChannel()
方法。
const voiceChannel = message.member.voiceChannel; // Keep in mind this may be undefined if
// they aren't connected to any channel.
if (voiceChannel && voiceChannel.id === "channel ID") {
message.member.setVoiceChannel(/* some other channel or ID */);
} else message.reply("You are not in the correct channel.");
确保从你的承诺中捕捉到任何错误。 请参阅此 MDN 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.