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

1.5K
Visualizações
discord.js v13 permissions.has() function not working (TypeError: Cannot read properties of undefined (reading 'has'))

I want to program a ban command for my Discord bot. I have this line where the bot should check if a user has the Administrator permission. If the user that should get banned has them, the bot doesn't ban the user and crashes. When I try to run this command I get this:

TypeError: Cannot read properties of undefined (reading 'has')

I don't understand why. Noone I asked could help me, I found nothing online, so I hope I can find here help.

My Code:

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

module.exports.run = async (Client, message, args) => {
  if (!message.member.roles.cache.some(role => role.id == 589850931785498624)) {
    return message.reply("You don't have the perms.");
  }

  const mention = message.mentions.users.first();

  if (!mention) {
    return message.reply('You need to tag a user!');
  }

  if (mention.permissions.has(Permissions.FLAGS.MANAGE_CHANNELS)) {
    return message.reply("You can't ban an Administrator!")
  }

  //message.guild.members.ban(mention);
}

module.exports.help = {
  name: "ban",
  aliases: ["b"],
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

"TypeError: Cannot read properties of undefined (reading 'has')" means that mention.permissions is undefined. It's because your mention variable is a User and only GuildMembers have permissions.

Another error is that you try to check if the role.id is equal to a number/integer but snowflakes (like 589850931785498624) should always be strings as these are greater than the MAX_SAFE_INTEGER.

module.exports.run = async (Client, message, args) => {
  if (!message.member.roles.cache.some((role) => role.id == '589850931785498624'))
    return message.reply("You don't have the perms.");

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

  if (!mentionedMember)
    return message.reply('You need to tag a user!');

  if (mentionedMember.permissions.has(Permissions.FLAGS.MANAGE_CHANNELS))
    return message.reply("You can't ban an Administrator!");

  message.guild.members.ban(mentionedMember);
};
over 4 years ago · Santiago Trujillo 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