I am trying to remove a role in my guild from many people. Yet, not everyone in the guild has that role, and there is a large number of them.
message.guild.members.cache.forEach(member => {
member.roles.remove("12345678901234");
});
This code works, but it is not efficient. The above code is very slow. Do you have a better code? Thank you!
You can remove any role you place here whenever you want by clicking the red Remove button to the right of the role in the Autorole List. Now, ensure that the Dyno Bot has a higher role on your server than the auto-assigned role, or it will not work.
I would delete the role and then create it again.
const role = message.guild.roles.cache.get("RoleID");
message.guild.roles.create({
data: {
name: role.name,
color: role.color,
hoist: role.hoist,
position: role.position,
permissions: role.permissions,
mentionable: role.mentionable
}
})
role.delete('I had to.')
It works very quickly, much faster than manually grabbing each member and removing the role, especially with a big server.
const Role = message.guild.roles.cache.get("RoleID");
Role.members.forEach((member, i) => { // Looping through the members of Role.
setTimeout(() => {
member.roles.remove(Role); // Removing the Role.
}, i * 1000);
});
I assume your code is slow because of Discord's API limits. You have no delays in your code, which means your code will be executed immediately.
The code I provided will remove a role from a member every 1 one second.
If you want to remove the role immediately, you need to delete it. It will be removed from everyone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With