javascript - how can i check the voice channel ID that the person is after they execute a command and move to other voice channe

I need to check the voice channel ID that the person is on after they execute a mand. If it is on this

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
Add a ment  | 

1 Answer 1

Reset to default 3

EDIT:

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745320455a4622420.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信