2

I got the error: TypeError: MOD.hasPermissions is not a function!

Can you please help me?

const commando = require('discord.js-commando');

class KickCommand extends commando.Command {

  constructor(client) {
    super(client, {
      name: 'kick',
      group: 'mod',
      memberName: 'kick',
      description: 'Kicks a member'
    });
  }

  async run(message, args, args2) {

    const MOD = message.author;
    const user = message.mentions.members.first()
    const reason = args2;

    if (MOD.hasPermissions('KICK_MEMBERS', true)) {
      user.kick(reason);
    } else {
      message.reply('You don\'t have permission to kick members!');
    }
  }
}

module.exports = KickCommand;
Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
j122j
  • 35
  • 2
  • 5

1 Answers1

4

To find out if the person has a permission, you use message.member.hasPermision (Since guild member is used for Permissions in a server.) The message.member is the same as message.author, but you use this to get the permissions of the person who sent the message.

const MOD = message.member;
const user = message.mentions.members.first()
const reason = args2;

if (MOD.hasPermissions('KICK_MEMBERS')) {

    user.kick(reason);
})
Swoods23
  • 373
  • 2
  • 5
  • 12
  • Thank you, but do you know how to add reason because its not just `const reason = args2;` – j122j Sep 18 '18 at 17:37
  • Click this to find a tutorial on how to use commando args. [Link](https://dragonfire535.gitbooks.io/discord-js-commando-beginners-guide/content/using-args-in-commands.html) – Swoods23 Sep 26 '18 at 16:32