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

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

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 Denunciar

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