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

76
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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