Create mute.js

This commit is contained in:
Carol Knieriem 2020-02-05 18:25:08 -05:00
parent 940898d14f
commit 9f16cf9f17
No known key found for this signature in database
GPG key ID: 932EC6A6BAEE122B

View file

@ -0,0 +1,43 @@
exports.run = async (client, message, args, level) => {
const user = message.mentions.users.first();
parseUser(message, user);
const modlog = client.channels.find('name', 'mod-log');
const caseNum = await client.caseNumber(client, modlog);
const muteRole = client.guilds.get(message.guild.id).roles.find('name', 'muted');
if (!modlog) return message.reply('I cannot find a mod-log channel').catch(console.error);
if (!muteRole) return message.reply('I cannot find a mute role').catch(console.error);
if (message.mentions.users.size < 1) return message.reply('You must mention someone to mute them.').catch(console.error);
const reason = args.splice(1, args.length).join(' ') || `Awaiting moderator's input. Use ${settings.prefix}reason ${caseNum} <reason>.`;
const embed = new RichEmbed()
.setColor(0x00AE86)
.setTimestamp()
.setDescription(`**Action:** Un/mute\n**Target:** ${user.tag}\n**Moderator:** ${message.author.tag}\n**Reason:** ${reason}`)
.setFooter(`Case ${caseNum}`);
if (!message.guild.member(client.user).hasPermission('MANAGE_ROLES_OR_PERMISSIONS')) return message.reply('I do not have the correct permissions.').catch(console.error);
if (message.guild.member(user).roles.has(muteRole.id)) {
message.guild.member(user).removeRole(muteRole).then(() => {
client.channels.get(modlog.id).send({embed}).catch(console.error);
});
} else {
message.guild.member(user).addRole(muteRole).then(() => {
client.channels.get(modlog.id).send({embed}).catch(console.error);
});
}
};
exports.conf = {
enabled: true,
guildOnly: true,
aliases: ["unmute"],
permLevel: "Moderator"
};
exports.help = {
name: "mute",
category: "Moderation",
description: "Mute or unmute a specified user.",
usage: "mute <user> <reason>"
};