From adbb1bd68094f5ae679728531f880ddab96a02be Mon Sep 17 00:00:00 2001 From: Kit Kasune Date: Tue, 20 Apr 2021 17:56:35 +0000 Subject: [PATCH] Add mute command file --- commands/moderation/mute..js | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 commands/moderation/mute..js diff --git a/commands/moderation/mute..js b/commands/moderation/mute..js new file mode 100644 index 0000000..192822e --- /dev/null +++ b/commands/moderation/mute..js @@ -0,0 +1,69 @@ +const Discord = require('discord.js'); + +const Mute = require('../../models/mute'); + +const muted = '717419538970312755'; + +module.exports = { + name: "mute", + aliases: ['m'], + meta: { + category: 'Moderation', + description: "Prevent a user from speaking for a designated amount of time", + syntax: '`mute <@user|userID> [duration] [reason]`', + extra: null, + guildOnly: true + }, + help: new Discord.MessageEmbed() + .setTitle("Help -> Muting") + .setDescription("Mutes a user (prevents them from speaking) for a designated amount of time") + .addField("Permissions", "You must have Manage Messages in your server in order to mute members.") + .addField("Duration Syntax", "By default, a member will be muted for one hour. However, you can specify m or h to mute a user for a set time. Ex: `mute @user 30m` or `mute @user 2h`. Max is 48h.") + .addField("Syntax", "`mute <@user|userID> [duration] [reason]`"), + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!args.length) {return message.channel.send(`Syntax: \`${prefix}mute <@user|userID> [duration] [reason]\``);} + if (!message.member.permissions.has("MANAGE_MESSAGES")) {return message.reply("You need to have Manage Messages permissions in this server to be able to do that.");} + if (!message.guild.me.permissions.has("MANAGE_ROLES")) {return message.reply("I don't have permissions to manage roles in this server, which I need to have in order to mute members.");} + const person = message.mentions.members.first() || message.guild.members.cache.get(args[0]); + if (message.guild.me.roles.highest.position <= person.roles.highest.position) {return message.reply("I don't have permissions to mute that member, as their highest role is equal to or above mine.");} + + if (person.roles.cache.has(muted)) {return message.reply("That person is already muted!");} + if (message.guild.roles.cache.get(muted).position <= person.roles.highest.position) {return message.reply("I don't have permissions to mute that member as their highest role is above or equal to the muted role!");} + + let udur = args[1] ? args[1].toLowerCase().trim() : '1h'; + let time; + if (args[1]) { + let dur = args[1].slice(0, args[1].length - 1); + if (!dur.match(/^\d+$/gm)) {return message.reply("That wasn't a valid time format!");} + dur = Number(dur) + let format = args[1].slice(args[1].length - 1).toLowerCase(); + if (!['h', 'm'].includes(format)) {return message.reply("That isn't a valid format for your mute time!");} + if ((format === 'h' && dur >= 48) || (format === 'm' && dur >= (48 * 60))) {return message.reply("That mute duration is too long! Try again.");} + time = format === 'h' ? new Date().getTime() + (dur * 1000 * 60 * 60) : new Date().getTime() + (dur * 1000 * 60); + } else {time = new Date().getTime() + (1000 * 60 * 60);} + + let reason = ''; + if (args[2]) {args.shift(); args.shift(); reason = args.join(" ").trim();} + + try { + person.roles.add("717419538970312755") + .then(() => message.channel.send("I've muted that member!") + .then(() => message.guild.channels.cache.get('830600344668602409').send(new Discord.MessageEmbed() + .setAuthor(message.member.displayName, message.author.avatarURL()) + .setTitle("Member Muted!") + .setDescription(`<@${person.id}> was muted!`) + .addField("Duration", udur, true) + .addField("Reason", reason.length ? reason : "No reason provided", true) + .setColor('c77dff') + .setFooter("Luno", client.user.avatarURL()) + .setTimestamp() + )) + ).catch(() => message.channel.send("There was an error while trying to mute that member. I may not have the correct permissions, or something else went wrong.")); + } catch {} + + let tm = new Mute({uid: person.id, until: time, mutedBy: message.author.id, reason: reason}); + tm.save(); + + return client.misc.cache.mute.set(person.id, time); + } +}; \ No newline at end of file