const Discord = require("discord.js"),
    bot = new Discord.Client();
    let pre = "?"
    bot.on("message", async msg => {
      var msgArray = msg.content.split(" ");
      var args = msgArray.slice(1);
      var prisonerRole = msg.guild.roles.find("name", "Prisoner");
        let command = msgArray[0];
      if (command == `${pre}roll`) {
        if (!msg.member.roles.has(prisonerRole.id)) {
        roll = Math.floor(Math.random()*6)+1;
        msg.reply(`You rolled a ${roll}`)
         } else {
           msg.reply(`HaHa NOOB, you're in prison you don't get priveleges!`)
        }
      }
      if (command == `${pre}kick`) {
        var leaderRole = msg.guild.roles.find("name", "LEADER");
        var co_leaderRole = msg.guild.roles.find("name", "CO-LEADER");
        if (msg.member.roles.has(leaderRole.id) ||
        msg.member.roles.has(co_leaderRole.id)) {
          var kickUser = msg.guild.member(msg.mentions.users.first());
          var kickReason = args.join(" ").slice(22);
          msg.guild.member(kickUser).kick();
          msg.channel.send(`${msg.author} has kicked ${kickUser}\nReason: ${kickReason}`);
    } else {
      return msg.reply("Ya pleb, you can't kick people!");
    }
  }
})
bot.login("token").then(function() {
    console.log('Good!')
  }, function(err) {
    console.log('Still good, as long as the process now exits.')
    bot.destroy()
  })


除了实际踢人之外,其他所有操作都有效。消息发疯了,它不会踢人。例如,当我键入?kick @BobNuggets#4576 inactive时,它说
@rishabhase has kicked @BobNuggetsReason: inactive
但这实际上并没有踢用户,这很奇怪,您能帮我吗?

最佳答案

更改

msg.guild.member(kickUser).kick();




kickUser.kick();


此外,请确保漫游器在层次结构中提升

关于javascript - 为什么不使用Discord.js踢人,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51460457/

10-10 00:41