I have a line of code for a discord bot to remove a specific named role and add a role named "muted" for a specific amount of time. Basically, the server can only have 3 roles, one that can issue the command, a "normal" rank with normal permissions, and then a "muted" role. and my code specifically removed the normal role and adds the muted role so they don't have any permissions.
Well I added my bot onto another server with more than 3 roles, I decided to give everyone the normal role and also make the muted role. when I run the command, it works, but since the people have other roles, it allows then to continue speaking even though the muted role is at the top priority.
My questions is that is there some code where I can just remove all their roles and add the muted role. and when the muted period is over, the muted role is removed and their previous roles are restored? here is my code below:
case 'mute':
if(!message.member.roles.cache.find(r => r.name === "Admin")) return message.channel.send('You dont have permissions to do that you clown')
let person = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[1]))
if(!person) return message.reply("User Doesn't Exist");
let mainrole = message.guild.roles.cache.find(role => role.name == "normal");
let muterole = message.guild.roles.cache.find(role => role.name == "muted");
if(!muterole) return message.reply("Role Doesn't Exist");
let time = args[2];
if(!time){
return message.reply("How Long?");
}
person.roles.remove(mainrole.id);
person.roles.add(muterole.id);
message.channel.send(`@${person.user.tag} has now been muted for ${ms(ms(time))}`);
setTimeout(function(){
person.roles.add(mainrole.id);
person.roles.remove(muterole.id);
message.channel.send(`@${person.user.tag} has now been unmuted`)
}, ms(time));
break;
case 'help':
const embed2 = new MessageEmbed()
.setTitle("How To Get Commands")
.setColor(0x00fff7)
.setDescription("Do /commands to get the list of commands");
message.author.send(embed2);
break;