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

92
Visualizações
guild.member.hasPermission is not a function

I was rummaging through an old source of discord.js from v11, and merged most of it to v12, mind you this script is erroring within the ready event, I'd prefer not to put it elsewhere.

This is what I have for now:

client.on('ready', async () => {
  log.success(`Authenticated as ${client.user.tag}`);
  client.user.setPresence({
    activity: {
      name: env.PRESENCE_ACTIVITY,
      type: env.PRESENCE_TYPE.toUpperCase(),
    },
  });
  const guild = client.guilds.cache.find((g) => g.id === '000000000');

  if (!guild)
    return console.log(`Can't find any guild with the ID "${env.GUILD_ID}"`);

  if (guild.member.hasPermission('ADMINISTRATOR', false)) {
    log.success("Bot has the 'ADMINISTRATOR' permission");
  } else 
    log.warn("Bot does not have 'ADMINISTRATOR' permission");

  client.guilds.cache
    .get(env.GUILD_ID)
    .roles.fetch()
    .then((roles) => {
      goodieRole = roles.cache.get(env.GOODIE_ROLE_ID);
    });
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There is no member property on guilds. If you want to get the bot as a member of that guild, you can fetch() them from guild.members. If you're using discord.js v12, you can use the hasPermission() method to check if the bot has an ADMINISTRATOR flag:

client.on('ready', async () => {
  log.success(`Authenticated as ${client.user.tag}`);
  client.user.setPresence({
    activity: {
      name: env.PRESENCE_ACTIVITY,
      type: env.PRESENCE_TYPE.toUpperCase(),
    },
  });
  const guild = client.guilds.cache.get(env.GUILD_ID);

  if (!guild)
    return console.log(`Can't find any guild with the ID "${env.GUILD_ID}"`);

  let botMember = await guild.members.fetch(client.user);

  if (botMember.hasPermission('ADMINISTRATOR', false)) {
    log.success("Bot has the 'ADMINISTRATOR' permission");
  } else
    log.warn("Bot does not have 'ADMINISTRATOR' permission");
  
  // ...
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