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

128
Views
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 answers
Answer question

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