I am trying to make a discord bot. When I type ?mute @role, I want my bot to create a 'Muted' role and remove the SEND_MESSAGES
and SPEAK
permissions for that role in every channel in a server. I have it to where it will add the role to the person, but so far I can't get it to set permissions. I'm using discord.js v12. My code is below. Bear with me because I'm not experienced at javascript and I haven't posted questions in StackOverflow before either.
if (!message.member.permissions.has('KICK_MEMBERS'))
return message.channel.send(
"*You don't have permission to use this command.*"
);
const role = message.guild.roles.cache.find((role) => role.name === 'Muted');
const member3 = message.guild.member(user);
if (!role) {
message.guild.roles
.create({
data: {
name: 'Muted',
color: 'GREY',
},
reason: 'Created role to mute member',
})
.then(console.log)
.catch(console.error);
}
if (!user) {
message.channel.send(`There's no person to mute tho`);
return;
}
if (member3.permissions.has('ADMINISTRATOR')) {
return message.channel.send(`I can't mute ${user} because he is staff`);
}
const roleMute = message.guild.roles.cache.find(
(role) => role.name === 'Muted'
);
message.guild.channels.cache.forEach((channel) => {
channel.updateOverwrite(channel.guild.roles.roleMute, {
SEND_MESSAGES: false,
SPEAK: false,
});
});
member3.roles.add(roleMute);