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

1.5K
Views
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 answers
Answer question

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