1

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

  }
});
Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
Marcus
  • 11
  • 1
  • 4
  • 1
    Please include code as snippets instead of images – Nino Filiu Dec 20 '18 at 22:09
  • Yes, it is easier for the people who are reading it to add it as snippets, because you can run snippets. To add a snippet, click the icon with a page and < > inside the page when you edit your answer. Paste your code in the text box that says Javascript, and press the "Save and Insert into Post Button". – Vappor Washmade Dec 21 '18 at 06:19
  • Oh alright, will do for next time! Thanks! – Marcus Dec 21 '18 at 11:01
  • @VapporWashmade In this case a snippet wouldn't be helpful: the code is for Node.js, and so it's not executable in the browser. – Federico Grandi Dec 22 '18 at 13:34

2 Answers2

0

For the kick command, you have to put an argument as a reason. Like this:

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

This is just like the ban command in the second image.
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.

Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
Vappor Washmade
  • 423
  • 4
  • 14
  • My kick function works and it needs a reason. I tried doing it without a reason and it didn't work. – Vappor Washmade Dec 21 '18 at 06:35
  • Also, you have to make sure the bot has a high enough role even if you don't have the reason. I don't think you need the reason, you just need the higher roles. – Vappor Washmade Dec 21 '18 at 06:37
  • I've done that and it still asks me to specify a user when I don't (which is what i wanted) however, when I do it doesn't ban the user (or kick). You can check my edit to see my current code. @VapporWashmade – Marcus Dec 21 '18 at 11:19
0

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.

Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
Marcus
  • 11
  • 1
  • 4