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

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

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 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