I need to check the voice channel ID that the person is on after they execute a mand. If it is on this channel, I want the bot to move to another desired channel.
var idchannel = member.get.voiceChannelID;
if(idchannel === "ID"){
//mand
// and i need to move this user to another channel.
}
else {
message.reply("You are not on the correct Channel.");
}
I need to check the voice channel ID that the person is on after they execute a mand. If it is on this channel, I want the bot to move to another desired channel.
var idchannel = member.get.voiceChannelID;
if(idchannel === "ID"){
//mand
// and i need to move this user to another channel.
}
else {
message.reply("You are not on the correct Channel.");
}
Share
Improve this question
asked Sep 29, 2019 at 19:47
JohnisonFJohnisonF
473 silver badges8 bronze badges
1 Answer
Reset to default 3EDIT:
As of Discord.js v12, my original answer will no longer work due to changes in voice related features.
Assuming you have a GuildMember member
, you are able to access voice related options using member.voice
. Through that VoiceState, you can refer to the VoiceState#channelID
property to access the ID of the VoiceChannel the member is connected to, if any. Putting it together, that's member.voice.channelID
.
As for moving the member to a specific channel, you'd do so using the VoiceState#setChannel()
method, so member.voice.setChannel(...)
.
The updated code would look something like the following:
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 ment
.catch(console.error);
}
ORIGINAL (v11):
You can refer to the voice channel a user is connected to using GuildMember.voiceChannel
. Then check the channel's id
property against the expected ID.
To move a member from one voice channel to another, you can use the GuildMember.setVoiceChannel()
method.
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.");
Make sure to catch any errors from your promises. See this MDN documentation.