I am trying to do a basic Discord.js bot, and I want to add a mute command.
I've tried this (the code below). That assigns a "foca muted you oof" role (I know the names are weird.) which doesn't allow you to do ANYTHING. But on my test account, even if it has that role assigned, I can still type messages extremely fine.
main.js:
} else if(cmd === `${prefix}mute`) {
if(!msg.member.hasPermission(["MANAGE_MESSAGES"])) return msg.channel.send("no no no, you can't manage messages. ok? alright?");
let toMute = msg.guild.member(msg.mentions.users.first());
if(toMute.user.username === msg.author.username) return msg.channel.send("oof. u can't mute urself.");
if(!toMute) return msg.channel.send("idk who to mute. does that person exist????");
let role = msg.guild.roles.find(r => r.name === "foca muted you oof");
if(!role) {
try {
role = await msg.guild.createRole({
name: "foca muted you oof",
color: "#000000",
permissions: []
});
msg.guild.channels.forEach(async (channel, id) => {
await channel.overwritePermissions(role, {
"SEND_MESSAGES": false,
"ADD_REACTIONS": false
});
})
} catch(e) {
console.log(e.stack);
}
}
if(toMute.roles.has(role.id)) return msg.channel.send("oof. this user is already muted. tried to do a bravery, huh?");
await toMute.addRole(role);
msg.channel.send(`${toMute.user.username} has been muted.`);
}
Can you tell me what's wrong?