DudeThatsErin

unmute.js

Nov 18th, 2020 (edited)
511
21 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const ms = require("ms");
  3.  
  4. module.exports = {
  5.   name: "unmute",
  6.   description: "This will unmute a user. Giving them the ability to speak again.\n**Note:** You have to have the MANAGE_MESSAGES permission to use this command.",
  7.   aliases: ['de-mute', 'mm', 'um', 'speak'],
  8.   usage: ".unmute @username or user ID [reason]",
  9.   inHelp: "yes",
  10.   execute (message, args) {
  11.  
  12.     // Defines and logs variables
  13.     const person = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
  14.     const reason = args.slice(2).join(" ");
  15.     const muterole = message.guild.roles.cache.find( r => r.name === 'Muted');
  16.     console.log('unmute reason:' + reason);
  17.     console.log('user:' + person);
  18.     console.log('user roles')
  19.    
  20.     // find person
  21.     if (!person) {
  22.       message.reply(":x: Couldn't find that member!");
  23.       return;
  24.     }
  25.     // Requiring reason
  26.     if (reason.length < 1) {
  27.       message.reply(':x: You must supply a reason for to unmute.');
  28.       return;
  29.     }
  30.    
  31.     // makes sure bot and user have roles.
  32.     if(!message.member.hasPermission("MANAGE_MEMBERS") || !message.guild.owner) {
  33.       message.channel.send(":no_entry_sign: You do not have the permission to use this command!");
  34.       return;
  35.     }
  36.  
  37.     if(!message.guild.me.hasPermission(["MANAGE_MEMBERS"])) {
  38.       message.channel.send(":no_entry_sign: I do not have the permission to add roles!");
  39.       return;
  40.     }
  41.  
  42.     if(!muterole) {
  43.         message.reply(':x: That user is not muted!');
  44.         return;
  45.     }
  46.  
  47.     person.roles.remove(muterole).catch(console.error);
  48.     message.channel.send(`:check: <@${person} has been unmuted and we were provided this reason: ${reason}.`);
  49.  
  50.   },
  51. };
  52.  
RAW Paste Data