1

该命令需要有理由才能工作,但是,即使我提及某人并给出理由,它仍然不会禁止。就像命令不被识别一样!

bot.on('message', async message => {
  if (message.content == prefix + "ban") {
    if (!message.member.roles.some(r => ["Administrator", "Co-owner"].includes(r.name)))
      return message.reply("Sorry, you don't have permissions to use this!");

    let member = message.mentions.members.first();
    if (!member)
      return message.reply("Please mention a valid member of this server");
    if (!member.bannable)
      return message.reply("I cannot ban this user! Do they have a higher role? Do I have ban permissions?");

    var reason = args.slice(1).join(' ');
    if (!reason) reason = "No reason provided";
    await member.ban(reason);

  }
});
4

2 回答 2

0

对于 kick 命令,您必须输入一个参数作为原因。像这样:

var reason = args.slice(1).join(' ');
member.kick(reason);

这就像第二张图片中的禁令命令一样。
如果您需要更多帮助或澄清,请问我。
如果这不起作用,请确保您的机器人在角色层次结构中具有足够高的角色。

于 2018-12-21T06:14:53.533 回答
0

终于让它工作了!这是我最后的代码:

bot.on('message', message => {
  let member = message.mentions.members.first();
  if (message.content.startsWith(prefix + "ban")) {
    if (!message.member.hasPermission('BAN_MEMBERS'))
      return message.reply("Sorry, you don't have permissions to use this!");
    if (!member)
      return message.reply("Please mention a valid member of this server");
    if (!member.bannable)
      return message.reply("I cannot ban this user! Do they have a higher role? Do I have ban permissions?");

    // V This line has been changed V
    var reason = message.content.split(' ').slice(2).join(' ');
    if (!reason) return message.reply("Please specify a reason!");
    member.ban(reason);
  }
});

一切都是因为原因!感谢所有帮助过我的人,这为我打开了更多命令的大门。

于 2018-12-21T14:01:23.430 回答