Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda