Advertisement
3MoSteve

Mute Command

Dec 4th, 2020 (edited)
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { readFileSync, writeFileSync } = require("fs")
  2. const muted = JSON.parse(readFileSync("./muted.json", "utf-8"));
  3. const ms = require("ms");
  4. const saveMuted = () => writeFileSync("./muted.json", JSON.stringify(muted, null, 2));
  5. //Code By 3Mo_Steve | Toxic Codes
  6. client.on("ready", () => {
  7.     setInterval(() => {
  8.         for (let i in muted) {
  9.             if (muted[i].time <= Date.now()) {
  10.                 const guild = client.guilds.cache.get(muted[i].guild);
  11.                 const member = guild.members.cache.get(muted[i].member);
  12.                 const role = guild.roles.cache.find(r => r.name == "Muted");
  13.                 if (role) member.roles.remove(role);
  14.                 delete muted[i];
  15.                 saveMuted();
  16.             }
  17.         }
  18.     }, 1000 * 5);
  19. });
  20. //Time formats:
  21. //1y = 1 Year
  22. //1m = 1 Month
  23. //1w = 1 Week
  24. //1d = 1 Day
  25. //1h = 1 Hour
  26. //1min = 1 Minute
  27. //1s = 1 second
  28. const reasons = [{
  29.         "reason": "سب",
  30.         "time": "5h"
  31.     },
  32.     {
  33.         "reason": "سبام بلشات",
  34.         "time": "10s"
  35.     },
  36.     {
  37.         "reason": "مدري",
  38.         "time": "1m"
  39.     }
  40. ]
  41.  
  42. client.on("message", message => {
  43.     if (!message.guild || message.author.bot) return false;
  44.     const args = message.content.split(" ");
  45.     if (args[0] == "$mute") {
  46.         if (!message.member.hasPermission ("MANAGE_ROLES")) return message.reply ("Access denied");
  47.         const member = message.mentions.members.first();
  48.         if (!member || (args[2] && !args[3])) return message.channel.send(`**Usage: ${args[0]} <mention>\nOr: ${args[0]} <mention> <time> <reason>**`);
  49.         const role = message.guild.roles.cache.find(r => r.name == "Muted");
  50.         if (!role) return message.reply("I can't find **Muted** role.");
  51.         if (!args[2]) {
  52.             if (reasons.length == 0) return message.reply(`There is no default reason please provide the time and reason.`);
  53.             var i = 1;
  54.             const embed = new MessageEmbed()
  55.                 .setColor("GREEN")
  56.                 .setTitle(`Select a reason`)
  57.                 .setDescription(`${reasons.map (re => `**${i++}** - ${re.reason}: ${re.time}`).join("\n")}`)
  58.                 .setThumbnail(message.author.displayAvatarURL())
  59.                 .setTimestamp().setFooter(`By: 3Mo_Steve`)
  60.             message.channel.send(embed).then(msg => {
  61.                 message.channel.awaitMessages((m => m.author.id == message.author.id && !isNaN(m.content) && parseInt(m.content) > 0 && parseInt(m.content) < reasons.length), {
  62.                     max: 1,
  63.                     time: 1000 * 60,
  64.                     errors: ["time"]
  65.                 }).then(collected => {
  66.                     const {
  67.                         reason,
  68.                         time
  69.                     } = reasons[(parseInt(collected.first().content) - 1)];
  70.                     muted[member.user.id] = {
  71.                         mod: message.author.id,
  72.                         member: member.user.id,
  73.                         guild: message.guild.id,
  74.                         reason,
  75.                         time: Date.now() + ms(time)
  76.                     }
  77.                     saveMuted();
  78.                     message.channel.send(`${member} muted from text.`);
  79.                     member.roles.add(role, `By: ${message.author.tag} | ${reason}`)
  80.                 }).catch(e => {
  81.                     console.log(e)
  82.                     msg.delete();
  83.                     message.reply(`Time out.`);
  84.                 })
  85.             })
  86.         } else {
  87.             muted[member.user.id] = {
  88.                 mod: message.author.id,
  89.                 member: member.user.id,
  90.                 guild: message.guild.id,
  91.                 reason: args.slice(3).join(" "),
  92.                 time: Date.now() + ms(args[2])
  93.             }
  94.             saveMuted();
  95.             member.roles.add(role, `By: ${message.author.tag} | ${args.slice(3).join(" ")}`)
  96.             message.channel.send(`${member} muted from text.`);
  97.         }
  98.     }
  99. });
  100. client.on ("guildMemberAdd", (toxic) => {
  101.     if (toxic.user.bot || !muted[toxic.user.id]) return;
  102.     if (muted[toxic.user.id].time < Date.now()) {
  103.         const role = toxic.guild.roles.cache.find (r => r.name == "Muted");
  104.         if (role) toxic.roles.add (role);
  105.     }
  106. }); //منشان ازا طلع من السيرفر ودخل
  107. //By 3Mo_Steve | Toxic Codes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement