如何在discord.js中断开用户与语音通道的连接?

时间:2019-08-26 00:43:58

标签: javascript discord.js disconnect

我不知道如何使用户离开语音通道。

我正在尝试进行验证,除离开语音通道部分外,我已经完成所有设置。

bot.on('voiceStateUpdate', (oldMember, newMember) => {
  let newUserChannel = newMember.voiceChannel
  let oldUserChannel = oldMember.voiceChannel
  var channel = bot.channels.get('614299678300831744');


  if(oldUserChannel === undefined && newUserChannel !== 615306755420717143) {
    channel.send(newMember + ' has been verified.');
    let role = newMember.guild.roles.find(role => role.name === "Verified");
    newMember.addRole(role);
    let verifyEmbed = new Discord.RichEmbed()
    .setAuthor("Verificaiton")
    .setDescription("You have been verified")
    .setFooter(newMember.guild.name)
    .setColor("#98AFC7")
    newMember.sendMessage(verifyEmbed);
    newMember.disconnect();
  }
});

我没有收到任何错误,但它应该使我与语音通道断开连接,但是不能吗?

4 个答案:

答案 0 :(得分:3)

不确定这是否仍然有用,但是自从更新以来,您现在可以执行以下操作。

L

请参阅VoiceState类方法newMember.member.voice.kick();

答案 1 :(得分:2)

问题在于.disconnect()不是GuildMember类的方法。可以在here上找到可以在GuildMember上使用的所有方法。

.disconnect()仅是voiceChannel上存在的方法,用于“断开语音连接,导致发出断开和关闭事件”。 1

据我所知,没有办法强制从语音通道中删除用户。

答案 2 :(得分:1)

使用newMember.disconnect();代替newMember.setVoiceChannel(null);

以下是相关的documentation

我在机器人上使用了它,并且效果很好。

答案 3 :(得分:1)

您可以使漫游器创建一个新的语音通道,将用户移至新创建的语音通道,删除该通道,从而断开用户的连接

<table width='600' cellpadding='0' cellspacing='0'>
  <tbody>
    <tr>
      <td>
        <a href='https://www.guitarcenter.com/Fender-American-Ultra-Stratocaster-Guitars.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' target='_blank'><img src='stratocaster.jpg' class='smallimg'></a>
        <div class='bold'> <b>Stratocaster <sup class='trademark'>®</sup> <p> Models</b>
          <a href='https://www.guitarcenter.com/Fender-American-Ultra-Stratocaster-Guitars.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' class='bold'>
            <p><a href='https://www.guitarcenter.com/Fender-American-Ultra-Stratocaster-Guitars.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' class='red'> Shop Now</p></a></div>
      </td>
      <td>
        <a href='https://www.guitarcenter.com/Fender-American-Ultra-Telecaster-Guitars.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' target='_blank'><img src='telecaster.jpg' class='smallimg'></a>
        <div class='bold'> <b>Telecaster <sup class='trademark'>®</sup> <p> Models</b>
          <p><a href='https://www.guitarcenter.com/Fender-American-Ultra-Telecaster-Guitars.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' class='red'> Shop Now</p></a></div>
      </td>
    </tr>

    <tr>
      <td>
        <a href='https://www.guitarcenter.com/Fender-American-Ultra-Jazzmaster-Guitars.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' target='_blank'><img src='jazzmaster.jpg' class='smallimg'></a>
        <div class='bold'> <b>Jazzmaster <sup class='trademark'>®</sup> <p> Models </b>
          <p><a href='https://www.guitarcenter.com/Fender-American-Ultra-Jazzmaster-Guitars.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' class='red'>&nbsp; Shop Now</p></a></div>
      </td>
      <td>
        <!-- Here is the code for the bass img -->
        <a href='https://www.guitarcenter.com/Fender-American-Ultra-Basses.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' target='_blank'><img src='BASS.jpg' class='smallimg'></a>
        <div class='bold'><b>Basses</b>
          <p><a href='https://www.guitarcenter.com/Fender-American-Ultra-Basses.gc?source=4TP9LHBA&dtm_em=d6a9d8b391c15fbb2e0fb42983408d85' class='red'> Shop Now</p></a></div>
      </td>
    </tr>
  </tbody>
</table>

正在添加randomnumber命令以在VC中创建一个随机数,这样就不会有任何具有相同名称的VC!