最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论