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. Also I'm going to make it disconnect you from whatever voice channel you are in so if you could save me the time on doing that I would also appreciate it.

Lioness100
  • 7,858
  • 5
  • 13
  • 46
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');
});

As for your following request:

Also I'm going to make it disconnect you from whatever voice channel you are in so if you could save me the time on doing that I would also appreciate it.

This is a simple "No". Stack Overflow is a question and answer site, not a code-writing service. So unless you have a question or an issue you just can't seem to figure out no matter what you try, people aren't going to help you by willingly write all the code you need for you for free.

Lioness100
  • 7,858
  • 5
  • 13
  • 46
T. Dirks
  • 3,396
  • 1
  • 18
  • 32