Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
Discord.js kick command permissions problem

So the last question I asked, I tried to use the sample code in MrMythical answer. This time, I encountered another problem:

if (message.member.permissions.has(Permissions.FLAGS.BAN_MEMBERS)){
                                   ^
    ReferenceError: Permissions is not defined

The code:

module.exports = new Command({
    name: "kick",
    description: "kick",

    async run(message, args, client) {
    if (message.member.permissions.has(Permissions.FLAGS.BAN_MEMBERS)) {
        if (message.mentions.members) {
            try {
                message.mentions.kick();
            } catch {
                message.reply("I don't have permission to ban " + message.mentions.members.first());
            }
        } else {
            message.reply("You cannot ban " + message.member.mentions.first());
        }
    }

    }
});

Let's say I deleted the if (message.member.permissions.has(Permissions.FLAGS.BAN_MEMBERS)), the message the returned when executing the command was I don't have permission to ban <insert_user_id>.

I'm kinda stuck here for a while, if you can help me, thank you so much.

Edit: I forgot to import the Permissions, so there's just "Don't have permissions to kick" now

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You will need to import Permissions from discord.js. You can import it at the top of the page, like this:

const { Permissions } = require('discord.js');

Also, message.mentions returns an object and it includes the mentioned members, channels, and roles. It won't have a kick() method and if you try to call it, it will throw an error. As you don't log the error in your catch block, you will have no idea what the error is; it will just send a reply saying "You cannot ban undefined".

You will need to check if there are mentioned members by checking message.mentions.members. It returns a collection; you can grab the first member by using first().

You can kick the first mentioned member like this:

const { Permissions } = require('discord.js');

module.exports = new Command({
  name: 'kick',
  description: 'kick',
  async run(message, args, client) {
    if (!message.member.permissions.has(Permissions.FLAGS.BAN_MEMBERS))
      return message.reply('You have no permission to ban members');

    if (!message.mentions.members)
      return message.reply('You need to mention a member to ban');

    let mentionedMember = message.mentions.members.first();

    try {
      mentionedMember.kick();
    } catch (err) {
      console.log(err);
      message.reply(`Oops, there was an error banning ${mentionedMember}`);
    }
  },
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!