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

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

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