How to remove a role from every member of the guild

Crist

How can I remove a role from every user inside a server, I tried using let everyone = message.guild.members.get and let everyone = message.guild.members but they both didn't work.

Here's the whole code:

const Discord = require("discord.js");
const errors = require("../utils/errors.js");

module.exports.run = async(bot, message, args) => {

  if (!message.member.hasPermission("MANAGE_ROLES")) return errors.noPerms(message, "MANAGE_ROLES");

  let role = message.guild.roles.find(`name`, `NSFW`);
  let everyone = message.guild.members.get
  if (args[0] == "help") {
    message.reply("Usage: !nsfwoff");
    return;

    message.channel.send(`NSFW has been turned to OFF, you're now safe from any kind of explicit content!`)

  }
  await (everyone.removeRole(role.id))
    .then(role => console.log(`NSFW OFF: ${message.guild.name}`))
    .catch(console.error);

  message.channel.send(`NSFW has been turned to ON, try !nsfwget to get the NSFW role!`);

}

module.exports.help = {
  name: "nsfwoff"
}
Ethan Mitchell

Just use the .forEach() function.

const Discord = require('discord.js');

module.exports.run = async (bot, message, args) => {
  if(!message.member.hasPermission('MANAGE_ROLES')) return noPermissions();
  let role = message.guild.roles.find(t => t.name == 'NSFW')
  message.guild.members.forEach(member => {
    if(!member.roles.find(t => t.name == 'NSFW')) return;
    member.removeRole(role.id);
        .then(function() {
        console.log(`Removed role from user ${member.user.tag}!`);
      })
  })
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I unban every member from a guild

How to remove role from user in guild discordjs V12?

How to add a Role when a member join in a Guild

How to remove a permission, a member, or a role?

Discord.js remove role of user from a specific guild

How to get member count of all members in every guild the bot is in

How to get ID of every role and member mentioned

Detecting if a guild.member is currently streaming and give or remove a role depending on streaming status

JDA: How to detect how a Member got removed from the guild?

How can i make my inrole command cache every member in the guild

How to get role names from member in discord

Ban member from other guild if banned in main guild

How to add a role to a user in a specific guild

discord.py remove every role from list of rols

How to remove member from OptionSet

How to remove a directory role member in MS Graph PowerShell module?

Collecting every guild and members returns "this.member.get" is not a function

How to check member role?

How to lock every channel of a guild with a command?

How to remove a role from specific user

how to remove roles of guild member TypeError: Cannot read properties of undefined (reading 'roles') discord.js v14

How to remove a character from every string in a list, based on the position where a specific character occurs in the first member of said list?

How to change role from member to admin in Apple developer program?

remove role on unreact can't get member

remove role id is member id discord py

How to remove an item from every dict in a list

How to remove character from every class in jQuery?

How to remove every occurrence from an array

How to remove every Nth element from an array

TOP Ranking

HotTag

Archive