Ryyan

Untitled

Aug 9th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.20 KB | None | 0 0
  1. if (command === "mute") {
  2. if (!message.member.hasPermission("MANAGE_ROLES") || !message.guild.owner) return message.channel.send("You dont have permission to use this command.");
  3.  
  4. if (!message.guild.me.hasPermission(["MANAGE_ROLES", "ADMINISTRATOR"])) return message.channel.send("I don't have permission to add roles!")
  5.  
  6. //define the reason and mutee
  7. let mutee = message.mentions.members.first() || message.guild.members.get(args[0]);
  8. if (!mutee) return message.channel.send("Please mention a user to be muted!");
  9.  
  10. let reason = args.slice(1).join(" ");
  11. if (!reason) reason = "No reason given"
  12.  
  13. //define mute role and if the mute role doesnt exist then create one
  14. let muterole = message.guild.roles.find(r => r.name === "Muted")
  15. if (!muterole) {
  16. try {
  17. muterole = await message.guild.createRole({
  18. name: "Muted",
  19. color: "#514f48",
  20. permissions: []
  21. })
  22. message.guild.channels.forEach(async (channel, id) => {
  23. await channel.overwritePermissions(muterole, {
  24. SEND_MESSAGES: false,
  25. ADD_REACTIONS: false,
  26. SEND_TTS_MESSAGES: false,
  27. ATTACH_FILES: false,
  28. SPEAK: false
  29. })
  30. })
  31. } catch (e) {
  32. console.log(e.stack);
  33.  
  34. }
  35. }
  36.  
  37.  
  38.  
  39. //add role to the mentioned user and also send the user a dm explaing where and why they were muted
  40. mutee.addRole(muterole.id).then(() => {
  41. message.delete()
  42. mutee.send(`Hello, you have been muted in ${message.guild.name} for: ${reason}`).catch(err => console.log(err))
  43. message.channel.send(`${mutee.user.username} was successfully muted.`)
  44. })
  45.  
  46.  
  47. if (command === "unmute") {
  48. if (!message.member.hasPermission("MANAGE_ROLES") || !message.guild.owner) return message.channel.send("You dont have permission to use this command.");
  49.  
  50. if (!message.guild.me.hasPermission(["MANAGE_ROLES", "ADMINISTRATOR"])) return message.channel.send("I don't have permission to add roles!")
  51.  
  52. //define the reason and unmutee
  53. let mutee = message.mentions.members.first() || message.guild.members.get(args[0]);
  54. if (!mutee) return message.channel.send("Please mention a user to be muted!");
  55.  
  56. let reason = args.slice(1).join(" ");
  57. if (!reason) reason = "No reason given"
  58.  
  59. //define mute role and if the mute role doesnt exist then send a message
  60. let muterole = message.guild.roles.find(r => r.name === "Muted")
  61. if (!muterole) return message.channel.send("That user is muted.")
  62.  
  63. //remove role to the mentioned user and also send the user a dm explaing where and why they were unmuted
  64. mutee.removeRole(muterole.id).then(() => {
  65. message.delete()
  66. message.channel.send(`${mutee.user.username} was unmuted!`)
  67. })
  68.  
  69. //send an embed to the modlogs channel
  70. let unmuteembed = new Discord.RichEmbed()
  71. .setColor(colors.redlight)
  72. .setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL)
  73. .addField("Moderation:", "unmute")
  74. .addField("Person who was moderated:", mutee.user.username)
  75. .addField("Moderator:", message.author.username)
  76. .addField("Reason:", reason)
  77. .addField("Date:", message.createdAt.toLocaleString())
  78.  
  79. let sChannel = message.guild.channels.find(c => c.name === "logs")
  80. sChannel.send(unmuteembed)
  81.  
  82. }
  83.  
  84.  
  85. if (command === "unban") {
  86. if (!message.member.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("You dont have permission to perform this command!")
  87.  
  88. if (isNaN(args[0])) return message.channel.send("You need to provide an ID.")
  89. let bannedMember = await client.fetchUser(args[0])
  90. if (!bannedMember) return message.channel.send("Please provide a user id to unban someone!")
  91.  
  92. let reason = args.slice(1).join(" ")
  93. if (!reason) reason = "No reason given!"
  94.  
  95. if (!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("I dont have permission to perform this command!") |
  96. message.delete()
  97. try {
  98. message.guild.unban(bannedMember, reason)
  99. message.channel.send(`${bannedMember.tag} has been unbanned from the guild!`)
  100. } catch (e) {
  101. console.log(e.message)
  102. }
  103.  
  104. let unbannedembed = new Discord.RichEmbed()
  105. .setColor("random")
  106. .setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL)
  107. .addField("Moderation:", "unban")
  108. .addField("Moderated on:", `${bannedMember.username} (${bannedMember.id})`)
  109. .addField("Moderator:", message.author.username)
  110. .addField("Reason:", reason)
  111. .addField("Date:", message.createdAt.toLocaleString())
  112.  
  113. let sChannel = message.guild.channels.find(c => c.name === "logs")
  114. sChannel.send(unbannedembed)
  115. }
  116.  
  117.  
  118. if (command === "ban") {
  119. //embeds, here.
  120. let noperms = new Discord.RichEmbed()
  121. .setTitle(`Error`)
  122. .setDescription(`You Do not have permissions to ban people.`)
  123. .setTimestamp()
  124. .setFooter("Sparky", client.user.avatarURL)
  125.  
  126. let nomember = new Discord.RichEmbed()
  127. .setTitle(`Error`)
  128. .setDescription('You did not mention a member to ban.')
  129. .setFooter("Sparky", client.user.avatarURL)
  130. .setTimestamp()
  131.  
  132. //https://support.discordapp.com/hc/article_attachments/115001756911/Administrator__1_.jpg
  133.  
  134. const bothasnoperms = new Discord.RichEmbed()
  135. .setTitle(`Error`)
  136. .addField(`I do not have ban permissions.`, `i need the permission below.`)
  137. .setImage("https://i.imgur.com/t6NGqwR.png")
  138. .setTimestamp()
  139. .setFooter("Sparky", client.user.avatarURL)
  140.  
  141. let icannotbanthem = new Discord.RichEmbed()
  142. .setTitle(`Error`)
  143. .setDescription(`I cannot ban this member! they might have a higher role than me or i don't have ban permissions.`)
  144. .setTimestamp()
  145. .setFooter("Sparky", client.user.avatarURL)
  146.  
  147.  
  148. const modlogs = client.channels.get("603746848964083752");
  149.  
  150. // Most of this command is identical to kick, except that here we'll only let admins do it.
  151. // In the real world mods could ban too, but this is just an example, right? ;)
  152.  
  153.  
  154. if (!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send(bothasnoperms)
  155.  
  156. if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send(noperms)
  157.  
  158.  
  159. let member = message.mentions.members.first();
  160. if (!member) return message.channel.send(erroremoji + "Please mention a member.")
  161. if (member.hasPermission("ADMINISTRATOR")) {
  162. message.channel.send(erroremoji + "That user is a mod/admin, I cannot ban them.")
  163. } else {
  164. if (!member.bannable)
  165. return message.channel.send(erroremoji + "I cannot ban this user! ");
  166.  
  167.  
  168. let reason = args.slice(1).join(' ');
  169. if (!reason) reason = "No reason provided";
  170.  
  171.  
  172.  
  173. await member.ban(reason)
  174. .catch(error => message.channel.send(erroremoji + `Sorry ${message.author} I couldn't ban because of : ${error}`));
  175.  
  176.  
  177. message.channel.send(successemoji + `${member}` + "was successfully banned.");
  178. }
  179. }
  180.  
  181. if (command === "tempmute") {
  182. if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.reply("You dont have permission to use this command.");
  183. let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
  184. if (!tomute) return message.reply("Please mention a user.");
  185. if (tomute.hasPermission("MANAGE_MESSAGES")) return message.reply("Can't mute them!");
  186. let reason = args.slice(2).join(" ");
  187. if (!reason) reason = "no reason provided"
  188.  
  189. let muterole = message.guild.roles.find(`name`, "Muted");
  190. //start of create role
  191. if (!muterole) {
  192. try {
  193. muterole = await message.guild.createRole({
  194. name: "muted",
  195. color: "#000000",
  196. permissions: []
  197. })
  198. message.guild.channels.forEach(async (channel, id) => {
  199. await channel.overwritePermissions(muterole, {
  200. SEND_MESSAGES: false,
  201. ADD_REACTIONS: false
  202. });
  203. });
  204. } catch (e) {
  205. console.log(e.stack);
  206. }
  207. }
  208. //end of create role
  209. let mutetime = args[1];
  210. if (!mutetime) return message.reply("You didn't specify a time!");
  211.  
  212. message.delete().catch(O_o => {});
  213.  
  214. try {
  215. await tomute.send(`Hi! You've been muted for ${mutetime}. Sorry!`)
  216. } catch (e) {
  217. message.channel.send(`A user has been muted... but their DMs are locked. They will be muted for ${mutetime}`)
  218. }
  219.  
  220. let muteembed = new Discord.RichEmbed()
  221. .setDescription(`Mute executed by ${message.author}`)
  222. .setColor("#eb9b34")
  223. .addField("Muted User", tomute)
  224. .addField("Muted in", message.channel)
  225. .addField("Time", message.createdAt)
  226. .addField("Length", mutetime)
  227. .addField("Reason", reason);
  228.  
  229. let channel = message.guild.channels.find(c => c.name === "logs");
  230. if (!channel) return message.reply("Please create a channel named 'logs'.");
  231. channel.send(muteembed);
  232.  
  233. await (tomute.addRole(muterole.id));
  234.  
  235. let mutemebed = new Discord.RichEmbed()
  236. .setTitle('Mute')
  237. .setDescription(`${tomute} was muted by ${message.author} because: ${reason} gg`)
  238. .setFooter("Sparky", client.user.avatarURL)
  239. .setColor("#00ff00")
  240.  
  241. message.channel.send(mutemebed)
  242.  
  243. setTimeout(function () {
  244. tomute.removeRole(muterole.id);
  245. }, ms(mutetime));
  246. }
  247.  
  248.  
  249. if (command === "addrole") {
  250.  
  251. let idonthaveperms = new Discord.RichEmbed()
  252. .setTitle('Error')
  253. .setDescription('I don\'t have the following permission needed to add roles: `MANAGE_ROLES`, or `ADMINISTRATOR`.')
  254. .setFooter("Sparky", client.user.avatarURL)
  255. .setColor("#00ff00")
  256.  
  257. let erroremoji = "<:errormate:609298253565001738>"
  258.  
  259.  
  260. if (!message.member.hasPermission(["MANAGE_ROLES", "ADMINISTRATOR"])) return message.channel.send("You dont have permission to perform this command!")
  261.  
  262. let rMember = message.mentions.members.first() || message.guild.members.find(m => m.user.tag === args[0]) || message.guild.members.get(args[0])
  263. if (!rMember) return message.channel.send("Please provide a user to add a role too.")
  264. let role = message.guild.roles.find(r => r.name == args[1]) || message.guild.roles.find(r => r.id == args[1]) || message.mentions.roles.first()
  265. if (!role) return message.channel.send("Please provide a role to add to said user.")
  266. let reason = args.slice(2).join(" ")
  267. if (!reason) reason = "no reason provided"
  268.  
  269. if (!message.guild.me.hasPermission(["MANAGE_ROLES", "ADMINISTRATOR"])) return message.channel.send(idonthaveperms)
  270.  
  271. if (rMember.roles.has(role.id)) {
  272. return message.channel.send(`${rMember.displayName}, already has the role!`)
  273. } else {
  274. await rMember.addRole(role.id).catch(e => console.log(e.message))
  275. message.channel.send(`The role, ${role.name}, has been added to ${rMember.displayName}.`)
  276. }
  277.  
  278. let addroleembed = new RichEmbed()
  279. .setColor(redlight)
  280. .setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL)
  281. .addField("Moderation:", "Addrole")
  282. .addField("Person who was moderated:", rMember.user.username)
  283. .addField("Moderator:", message.author.username)
  284. .addField("Reason:", reason)
  285. .addField("Date:", message.createdAt.toLocaleString())
  286.  
  287. let sChannel = message.guild.channels.find(c => c.name === "logs")
  288. sChannel.send(addroleembed)
  289.  
  290. }
  291.  
  292. if (command === "removerole") {
  293. if (!message.member.hasPermission(["MANAGE_ROLES", "ADMINISTRATOR"])) return message.channel.send("You dont have permission to perform this command!")
  294.  
  295. let rMember = message.mentions.members.first() || message.guild.members.find(m => m.user.tag === args[0]) || message.guild.members.get(args[0])
  296. if (!rMember) return message.channel.send("Please provide a user to remove a role too.")
  297. let role = message.guild.roles.find(r => r.name == args[1]) || message.guild.roles.find(r => r.id == args[1]) || message.mentions.roles.first()
  298. if (!role) return message.channel.send("Please provide a role to remove from said user.")
  299. let reason = args.slice(2).join(" ")
  300. if (!reason) reason = "no reason provided"
  301.  
  302. if (!message.guild.me.hasPermission(["MANAGE_ROLES", "ADMINISTRATOR"])) return message.channel.send("I don't have permission to perform this command.")
  303.  
  304. if (!rMember.roles.has(role.id)) {
  305. return message.channel.send(`${rMember.displayName}, doesnt have the role!`)
  306. } else {
  307. await rMember.removeRole(role.id).catch(e => console.log(e.message))
  308. message.channel.send(`The role, ${role.name}, has been removed from ${rMember.displayName}.`)
  309. }
  310.  
  311. let removeroleembed = new Discord.RichEmbed()
  312. .setColor(redlight)
  313. .setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL)
  314. .addField("Moderation:", "Addrole")
  315. .addField("Person who was moderated", rMember.user.username)
  316. .addField("Moderator:", message.author.username)
  317. .addField("Reason:", reason)
  318. .addField("Date:", message.createdAt.toLocaleString())
  319.  
  320. let sChannel = message.guild.channels.find(c => c.name === "logs")
  321. sChannel.send(removeroleembed)
  322. }
Advertisement
Add Comment
Please, Sign In to add comment