Monday, December 11, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  110] [ 1]  / answers: 1 / hits: 8230  / 4 Years ago, sun, september 29, 2019, 12:00:00

I need to check the voice channel ID that the person is on after they execute a command. If it is on this channel, I want the bot to move to another desired channel.

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

More From » node.js



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
} else {
message.reply('You are not in the correct channel.') // see last comment


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 && === "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.

[#6082] Thursday, September 26, 2019, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 113
Total Questions: 100
Total Answers: 115

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago