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

193
Views
Conditional Role Discord.js

Basically, what I'm trying to do is have it so that if a member in my server sends a message they get the "Active" role. I have another bot doing that already. The issue is, I want to assign an "Inactive" role to anyone who hasn't sent a message. The way I have it set up (I think) is that when a member's roles are changed, it checks to see if the member has the "Active" role and removes the "Inactive" role from them. Inversely, if the "Active" role is removed, it's supposed to add the "Inactive" role.

    client.on("guildMemberUpdate", (oldMember, newMember) => {
  //Has Acitve, remove Inactive.
  if (newMember.roles.cache.has(971885336680616007)) {
    newMember.roles.remove(971903053626241034);
  }
  //Doesn't have Active, add Inactive.
  elseif (!newMember.roles.cache.has(971885336680616007))
    newMember.roles.add(971903053626241034)
}) 

This is the code I'm using but I feel like I must've done something incorrectly because I can't get it to work

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The reason why you might not be able to add the roles and why you might get an error is because, when checking if the member has a role, instead of passing a string, you are passing a number. One error you might get from doing it like this is: TypeError [INVALID_TYPE]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes. So to fix your error, all you have to do is pass all the role ids as strings so that your final code will look something like this:

client.on("guildMemberUpdate", (oldMember, newMember) => {
    // User has active role, remove inactive role
    if (newMember.roles.cache.has('971885336680616007')) {
        newMember.roles.remove('971903053626241034');
    }
    // User doesn't have active role, add inactive role
    else if (!newMember.roles.cache.has('971885336680616007')) {
        newMember.roles.add('971903053626241034')
    }
}) 
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!