0

So I found this thread here How to remove a role from every member of the guild but when I tried the answer someone gave I got an error in the "." of the .then and I tried a different route.

const EEEE = '153587203488874496';
let membersWithRole = message.guild.roles.cache.get('766141415759151154').members;
if (message.author.id === EEEE)
 membersWithRole.roles.remove('766141415759151154');
message.channel.send(`${message.author.username} kicks you out of their room`);

Now with this I'm getting the error "TypeError: Cannot read property 'remove' of undefined" so I'm not sure what to do.

Dharman
  • 30,962
  • 25
  • 85
  • 135
EzyZombi
  • 1
  • 2

1 Answers1

1

The error states that membersWithRole.roles is undefined, which is true. Calling .members on a role (like you did with message.guild.roles.cache.get('766141415759151154').members;) returns a Collection of GuildMembers. If you want to remove a role for each GuildMember, you can use the Collection.prototype.each method. See the example code below and give it a try:

membersWithRole.each((memberWithRole) => {
  memberWithRole.roles.remove('766141415759151154');
});
Dharman
  • 30,962
  • 25
  • 85
  • 135
T. Dirks
  • 3,566
  • 1
  • 19
  • 34