Advertisement
Guest User

Untitled

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