Advertisement
Guest User

Untitled

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