Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda