My code is like this:
let rMember = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get([0]));
let crewmate = message.guild.roles.cache.get("752639666393710614");
rMember.roles.set([crewmate]);
The code works correctly, but if the person has the role of "Server Booster", it gives a Missing Permission error.
How can I get him to take all roles except the "server booster" role?
Nobody can assign/reassign booster roles or bot roles. You can prevent any errors coming from this by adding any managed
roles (roles you can't assign/reassign) to the array.
let rMember = message.guild.member(
message.mentions.users.first() || message.guild.members.cache.get([0])
);
let crewmate = message.guild.roles.cache.get('752639666393710614');
rMember.roles.set([
crewmate, // add the crewmate role
...rMember.roles.cache.filter((role) => role.managed).array(), // and any existing `managed` roles
]);
The role "Server Booster" can only be given when a user boost the server.
Good coding.
I found the answer to my problem. It doesn't give an error when I do it this way.
let rMember = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get([0]));
const crewmate = ["752639666393710614"];
if(rMember.roles.cache.has("server booster role id")) {
roles[1] = "server booster role id";
}
rMember.roles.set(crewmate);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.