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

202
Visualizações
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 Respostas
Responde à pergunta

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