所以我有这个方法可以从所有拥有它的成员中删除角色
client.on('message', msg => {
var content = msg.content;
var prefix = content.substring(0,1);
if(prefix=='_'){
var args = content.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd){
case 'role':
var mentionedUser = msg.mentions.members.first();
if(args[0] == 'removeFromAll'){
var role = msg.mentions.roles.first();
if(role == null) {
Embeds.removeFromAllNoRole(msg)
break;
}
let roleID = role.id;
var membersWithRole = msg.guild.roles.cache.get(roleID).members;
membersWithRole.forEach(member => {
member.roles.remove(roleID).catch(console.error);
});
membersWithRole = msg.guild.roles.cache.get(roleID).members;
console.log(membersWithRole)
if(membersWithRole.size === 0){
Embeds.removeFromAllFinished(msg)
}
else{
Embeds.removeFromAllFailed(msg)
}
}
break;
}
}
});
但是,当我从所有人中删除角色后更新 membersWithRole 变量时,似乎该变量没有更新。它仍然包含在删除角色之前拥有该角色的所有成员。这是为什么,如何解决?