Advertisement
3MoSteve

Mute & Unmute Commands

Feb 17th, 2021
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. const { readFileSync, writeFileSync } = require("fs");
  2. const mutes = JSON.parse (readFileSync("./mutes.json", "utf-8"));
  3. const saveMutes = () => writeFileSync("./mutes.json", JSON.stringify(mutes, null, 2));
  4. let prefix = "$";
  5. const ms = require("ms");
  6. client.on ("ready", () => {
  7. (function check() {
  8. for (let i in mutes) {
  9. if (mutes[i].time <= Date.now()) {
  10. let guild = client.guilds.cache.get(mutes[i].guild);
  11. let member = guild?.members.cache.get(mutes[i].target);
  12. let role = guild?.roles.cache.find(r => r.name == "Muted");
  13. if (guild && member) {
  14. if (role) member.roles.remove(role, "Time out.");
  15. }
  16. delete mutes[i];
  17. saveMutes();
  18. }
  19. }
  20. setTimeout(() => check(), 1000 * 5);
  21. })();
  22. })
  23. client.on ("guildMemberAdd", async (member) => {
  24. if (mutes[member.id + member.guild.id]) {
  25. let role = member.guild.roles.cache.find (r => r.name == "Muted");
  26. if (!role) {
  27. role = await member.guild.roles.create({
  28. data: {
  29. name: "Muted",
  30. permissions: 0
  31. },
  32. reason: "evetS_oM3 yB | dnammoc etuM roF".split("").reverse().join("")
  33. });
  34. member.guild.channels.cache.filter(c => "text" == c.type).forEach(c => {
  35. c.overwritePermissions ([
  36. {
  37. id: role.id,
  38. deny: ["SEND_MESSAGES", "ADD_REACTIONS"]
  39. }
  40. ])
  41. });
  42. }
  43. member.roles.add (role, "evetS_oM3 yB | niojeRitnA".split("").reverse());
  44. }
  45. })
  46. client.on ("message", async message => {
  47. if (!message.guild || message.author.bot || !message.content.startsWith(prefix)) return false;
  48. const [command, ...args] = message.content.trim().slice(prefix.length).split(" ");
  49. let role = message.guild.roles.cache.find (r => r.name == "Muted");
  50. let member = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
  51. console.log (command)
  52. switch (command) {
  53. case "unmute":
  54. if (!message.member.hasPermission ("MANAGE_ROLES")) return message.reply ("Access denieed");
  55. if (!role) return message.reply ("Muted role not found.");
  56. if (!member) return message.reply ("Please mention a member");
  57. if (!member.roles.cache.get(role.id) && !mutes[member.id + message.guild.id]) return message.channel.send (`**This Member is not muted.**`);
  58. if (member.roles.cache.get(role.id)) member.roles.remove (role);
  59. if (mutes[member.id + message.guild.id]){
  60. delete mutes[member.id + message.guild.id];
  61. saveMutes();
  62. }
  63. message.channel.send (`${member} unmuted.`);
  64. break;
  65. case "mute":
  66. if (!message.member.hasPermission ("MANAGE_ROLES")) return message.reply ("Access denieed");
  67. if (!role) return message.reply ("Muted role not found.");
  68. if (!member) return message.reply ("Please mention a member");
  69. if (member.roles.highest > message.member.roles.highest) return message.reply (`You can't mute ${member}`)
  70. if (member.roles.cache.get (role.id)) return message.channel.send (`${member} is already muted.`);
  71. if (!args[1]) return message.reply (`Specify a time: 1s,1min,1h,1d,1w,1m,1y`);
  72. let reason = args[2] ? args.slice(2).join(" ") : "No Reason";
  73. member.roles.add (role, `By: ${message.author.tag} | ${reason} | ${args[1]}`)
  74. if (mutes[member.id+message.guild.id]) {
  75. delete mutes[member.id+message.guild.id];
  76. }
  77. mutes[member.id+message.guild.id] = {
  78. time: Date.now() + ms (args[1]),
  79. by: message.author.id,
  80. guild: message.guild.id,
  81. target: member.id
  82. }
  83. saveMutes ();
  84. message.channel.send (`${member} muted from text.`);
  85.  
  86. break;
  87. }
  88. });
  89. /*
  90. Copyright Toxic Codes 2021. All rights reserved
  91. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement