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

70
Views
I'm trying to fetch the bot's permissions to check if the command will be able to run

I'm trying to fetch the bot's permissions to check if the command will be able to run. I have the following code:

let botid = "idbot"
let bot = client.users.cache.get(botid)
if (!bot.permissions.has("ADMINISTRATOR")) 
  return message.channel.send("Para mim poder liberar a função de registro eu preciso da permissão **Administrador**, por favor peça para algum **Staff** do servidor configurar, Obrigado.")

I receive the following error:

if (!bot.permissions.has("ADMINISTRATOR"))
                    ^
TypeError: Cannot read properties of undefined (reading 'has')
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Because bot as you defined it is just a User, meaning it just has informations like it's tag, username, servers it is in etc.. what you want is a GuildMember, it's the same person but on a specific server, it has roles, a hoist color and permissions which is what you're searching for :

let bot = message.guild.me; // The bot's GuildMember object
if (!bot.permissions.has("ADMINISTRATOR")) return message.reply('I am not an admin!')
about 4 years ago · Juan Pablo Isaza Report

0

bot is a User and Users don't have permissions, only GuildMembers do. For this, you'll need to grab the Guild (either by getting by its ID, or just using message.guild). guild#me will be your bot as a GuildMember of that guild.

You could also just use the fetch method on guild.members. Anyway, you'll need a guild to check your bot's permissions.

let botid = 'idbot';
let guild = client.guilds.cache.get('GUILD_ID');
// OR get it from the message
let { guild } = message;

let bot = guild.me;
// OR fetch it from members
let bot = await guild.members.fetch(botid);

if (!bot.permissions.has('ADMINISTRATOR'))
  return message.channel.send(
    'Para mim poder liberar a função de registro eu preciso da permissão **Administrador**, por favor peça para algum **Staff** do servidor configurar, Obrigado.',
  );
about 4 years ago · Juan Pablo Isaza 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!