Skip to content

Discord.js remove roles

I have this issue on my bot command. It doesn’t remove any other specified roles other than the first defined one.

if (args[0] === "yes") {
    const exists = users.find((u) => === message.member.user.tag);
    if (!exists) {
        return"You are not registered into a clan.");
    await RegistryModel.findOneAndDelete({ name: message.member.user.tag });

    let gangroles = message.guild.roles.cache.find(role => === "Eliminaries", "Street Legends/Locos", "The Circle", "Critical Killers", "Crime Master", "Brazil Printer Mafia", "Saint Bude", "Communist Party Of Nevada", "The Cola Association", "National Choppa", "Squad Of Skilled", "Myth", "Shelby Family", "Shooters Family Gang", "Terminator", "Century Street Gang", "Phoenix Core", "Knights of Despair", "Garuda Team", "Sando Gang", "Liberators", "Celestial Blue", "Mystic", "Taniman", "Crimson", "Black Blood Mafia", "Crypts", "Terror", "Hydras");
    message.member.roles.remove( => console.log(err));

This is the part where everything is defined.


Your callback function for find() is incorrect, and actually find() returns the first found element in an array. You could use .filter() to get a collection of elements instead and use the .includes() method to check if the role name is in the list provided.

if (args[0] === 'yes') {
  const exists = users.find((u) => === message.member.user.tag);
  if (!exists) {
    return'You are not registered into a clan.');
  await RegistryModel.findOneAndDelete({ name: message.member.user.tag });

  const list = [
    'Street Legends/Locos',
    'The Circle',
    'Critical Killers',
    'Crime Master',
    'Brazil Printer Mafia',
    'Saint Bude',
    'Communist Party Of Nevada',
    'The Cola Association',
    'National Choppa',
    'Squad Of Skilled',
    'Shelby Family',
    'Shooters Family Gang',
    'Century Street Gang',
    'Phoenix Core',
    'Knights of Despair',
    'Garuda Team',
    'Sando Gang',
    'Celestial Blue',
    'Black Blood Mafia',

  // get a collection of roles that have names included in the list array
  let gangroles = message.guild.roles.cache.filter((role) =>
  // remove every matching roles
  gangroles.each((r) => {
    message.member.roles.remove( => console.log(err));