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

138
Visualizações
How to check if a message author has a role?

I am trying to code a bot for a game idea my friends and I have. The command I'm working on is the score adjuster. Obviously though, I only want moderators to have access to this command.

I have read several threads and tried several methods to check for a role though, and all close the script with this error:

if (message.member.roles.has(modRole))                  

TypeError: Cannot read properties of null (reading 'roles')

This is the last code I tried:

bot.on("message", (message) => {
    let args = message.content.toLowerCase().substring(PREFIX.length).split(" ");

    if (args[0] === "adjust" && args[1] !== "help") {
        if (message.member.roles.has("modRoleID")) {
            // Adjust command here
        }
    }
});

Why is the bot not able to read .roles()?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So I never got .roles to work. And I wasn't about to recode the entire bot to match v13, so here's what I did:

I just set an array to contain all the moderator user id's, and then checked if the author was a moderator, like so:

const mods = ['userID_1','userID_2'];

bot.on("message", (message) => {

    let args = message.content.toLowerCase().substring(PREFIX.length).split(" ");

    if (args[0] === "adjust" && args[1] !== "help") {
        if (!mods.includes(message.author.id)) return message.channel.send("You do not have permission to use that command!").then()
        //Adjust command here
    }
});
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