Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda