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

226
Visualizações
How to remove a specific role from everyone that has it Discord.js v12

Using Discord.js (V12)

I am currently trying to create a script that makes it so when someone says "what" the bot responds with "You are stuck with it!" then gives the user a role. But I want it so when the next person says what, it removes that role from the previous wielder. I currently have it working where it can add the role but not remove it from the previous person.

Here is my current working code:

module.exports = {
  name: 'what',
  description: 'Responds with You are stuck with it and adds role!',
  execute(message, args) {
    message.channel.send('You are stuck with it!');
    message.member.roles.add('886996311117795429')
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem of declaring variable inside your code like @Cannicide suggested is that if the bot goes down and you need to boot it up again, that variable will be lost.

The easiest way of having the data saved even after restarts is by using quick.db

//your other stuff if you have any
const db = require('quick.db')

module.exports = {
  name: 'what',
  description: 'Responds with You are stuck with it and adds role!',
  execute(message, args) {
    message.channel.send('You are stuck with it!');
    message.member.roles.add('886996311117795429')
    if(db.get('previousRoleUser')){
          let prevUser = message.guild.members.cache.find(m => m.id === db.get('previousRoleUser'));
          if(prevUser){
                prevUser.roles.remove('886996311117795429')
          }
    db.set('previousRoleUser', message.author.id)
  }
}

The above code is just an example, that is not tested. But I think it would work some how like that. Just set the value of the previous user to quick.db and then fetch the info from there when you want to use it.

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