As stated. I'm trying to create a temporary mute command for my Discord bot. The problem I ran into is it creates the role muted but the user can still write messages even though I've changed the perms. And on top of that I'm getting the following deprecation warning:
(node:15956) DeprecationWarning: Collection#find: pass a function instead
const Discord = require("discord.js");
const ms = require("ms");
module.exports.run = async (bot, message, args) => {
//!tempmute @user 1s/m/h/d
let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if(!tomute) return message.reply("Couldn't find user.");
if(tomute.hasPermission("MANAGE_MESSAGES")) return message.reply("Can't mute them!");
let muterole = message.guild.roles.find(`name`, "muted");
//start of create role
if(!muterole){
try{
muterole = await message.guild.createRole({
name: "muted",
color: "#000000",
permissions:[]
})
message.guild.channels.forEach(async (channel, id) => {
await channel.overwritePermissions(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false
});
});
}catch(e){
console.log(e.stack);
}
}
//end of create role
let mutetime = args[1];
if(!mutetime) return message.reply("You didn't specify a time!");
await(tomute.addRole(muterole.id));
message.reply(`<@${tomute.id}> has been muted for ${ms(ms(mutetime))}`);
setTimeout(function(){
tomute.removeRole(muterole.id);
message.channel.send(`<@${tomute.id}> has been unmuted!`);
}, ms(mutetime));
//end of module
}
module.exports.help = {
name: "tempmute"
}