简体   繁体   English

禁止命令未被识别

[英]Ban command is not being recognized

The command requires a reason to work, however, it still does not ban even if I mention someone and give a reason. 该命令要求有一个起作用的理由,但是,即使我提到某人并给出了理由,它仍然没有被禁止。 It's like the command isn't recognized! 就像命令无法识别!

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);

  }
});

For the kick command, you have to put an argument as a reason. 对于kick命令,您必须输入一个参数作为理由。 Like this: 像这样:

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

This is just like the ban command in the second image. 就像第二张图片中的ban命令一样。
If you need more help or clarification, ask me. 如果您需要更多帮助或说明,请问我。
If this doesn't work, make sure your bot has a high enough role in the role hierarchy. 如果这不起作用,请确保您的机器人在角色层次结构中具有足够高的角色。

Finally got it to work! 终于让它工作了! This was my code at the end: 这是我最后的代码:

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);
  }
});

It was all because of the reason! 都是因为原因! Thanks to everyone who helped me, this opened doors for a lot more commands for me. 感谢所有帮助我的人,这为我打开了更多的命令之门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM