Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. const { RichEmbed } = require("discord.js")
  2. module.exports.config = {
  3. name: "mute",
  4. description: "Mutes a member in the discord!",
  5. usage: "!mute <user> <reason>",
  6. category: "moderation",
  7. accessableby: "Members",
  8. aliases: ["m", "nospeak"]
  9. }
  10. run: async (bot, message, args) => {
  11. // check if the command caller has permission to use the command
  12. if(!message.member.hasPermission("MANAGE_ROLES") || !message.guild.owner) return message.channel.send("You dont have permission to use this command.");
  13.  
  14. if(!message.guild.me.hasPermission(["MANAGE_ROLES", "ADMINISTRATOR"])) return message.channel.send("I don't have permission to add roles!")
  15.  
  16. //define the reason and mutee
  17. let mutee = message.mentions.members.first() || message.guild.members.get(args[0]);
  18. if(!mutee) return message.channel.send("Please supply a user to be muted!");
  19.  
  20. let reason = args.slice(1).join(" ");
  21. if(!reason) reason = "No reason given"
  22.  
  23. //define mute role and if the mute role doesnt exist then create one
  24. let muterole = message.guild.roles.find(r => r.name === "Muted")
  25. if(!muterole) {
  26. try{
  27. muterole = await message.guild.createRole({
  28. name: "Muted",
  29. color: "#514f48",
  30. permissions: []
  31. })
  32. message.guild.channels.forEach(async (channel, id) => {
  33. await channel.overwritePermissions(muterole, {
  34. SEND_MESSAGES: false,
  35. ADD_REACTIONS: false,
  36. SEND_TTS_MESSAGES: false,
  37. ATTACH_FILES: false,
  38. SPEAK: false
  39. })
  40. })
  41. } catch(e) {
  42. console.log(e.stack);
  43. }
  44. }
  45.  
  46. //add role to the mentioned user and also send the user a dm explaing where and why they were muted
  47. mutee.addRole(muterole.id).then(() => {
  48. message.delete()
  49. mutee.send(`Hello, you have been in ${message.guild.name} for: ${reason}`).catch(err => console.log(err))
  50. message.channel.send(`${mutee.user.username} was successfully muted.`)
  51. })
  52.  
  53. //send an embed to the modlogs channel
  54. let embed = new RichEmbed()
  55. .setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL)
  56. .addField("Moderation:", "mute")
  57. .addField("Mutee:", mutee.user.username)
  58. .addField("Moderator:", message.author.username)
  59. .addField("Reason:", reason)
  60. .addField("Date:", message.createdAt.toLocaleString())
  61.  
  62. let sChannel = message.guild.channels.find(c => c.name === "tut-modlogs")
  63. sChannel.send(embed)
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement