Advertisement
Templuzy

warn.js

Feb 3rd, 2021 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
  3. const guild = client.guilds.cache.get("790189687750918154");
  4. const fs = require('fs');
  5. const ms = require('ms');
  6. let warns = JSON.parse(fs.readFileSync("./warnings.json", "utf8"));
  7.  
  8.  
  9.  
  10. module.exports = {
  11.     name: 'warn',
  12.     description: 'Warns a member',
  13.     async execute(client, message, args,){
  14.         if(!message.member.hasPermission("MANAGE_MEMBERS")) return message.reply("Imagine having a permission to do that!");
  15.         let wUser = message.guild.member(message.mentions.users.first());
  16.         if(!wUser) return message.reply("Mention a member stupid!");
  17.         let reason = args.join(" ").slice(22);
  18.  
  19.         if(!warns[wUser.id]) warns[wUser.id] = {
  20.             warns: 0
  21.         };
  22.  
  23.         warns[wUser.id].warns++;
  24.  
  25.         fs.writeFile("./warnings.json", JSON.stringify(warns), (err) => {
  26.             if(err) console.log(err);
  27.         });
  28.  
  29.         let warnEmbed = new Discord.MessageEmbed()
  30.         .setDescription("Warns")
  31.         .setAuthor(message.author.username)
  32.         .setColor("#dbaa40")
  33.         .addFields( {name: "Warning", value:`"Warned user", ${wUser.tag}`},
  34.                     {name: '\u200B', value:`"Number of infractons" ${warns[wUser.id].warns}`},
  35.                     {name: '\u200B', value:`"Reason", ${reason}`},
  36.                     {name: '\u200B', value:`"Warned in", ${message.channel}`},
  37.         )
  38.         //.addField("Warned in", message.channel)
  39.         //.addField("Number of Warnings", warns[wUser.id].warns)
  40.         //.addField("Reason", reason)
  41.         //.addField("Warned user", wUser.tag)
  42.  
  43.         let warnchannel = guild.channel.cache.get("❗│warnings")
  44.         if(!warnchannel) return message.reply("Didn't find the channel");
  45.  
  46.         warnchannel.send(warnEmbed);
  47.  
  48.         if(warns[wUser.id].warns == 5){
  49.             let muterole = message.guild.roles.cache.find(name => name.name === 'Muted');
  50.             let mutetime = "24h";
  51.             await(wUser.addRole(muterole.id));
  52.             message.channel.send(`${wUser.tag} has been temporarily muted because of continuous infractions! If you think there is a mistake, open a ticket in ✉│contact-staff!`);
  53.  
  54.             setTimeout(function(){
  55.                 wUser.removeRole(muterole.id)
  56.                 message.channel.send(`${wUser.tag} is now unmuted! Try not to be a bad boy/girl nex time!`)
  57.             })
  58.         }
  59.  
  60.         if(warns[wUser.id].warns == 10){
  61.             message.guild.member(wUser).kick(reason);
  62.             message.channel.send(`${wUser.tag} has been kicked because of continuous infractions! If you think there is a mistake, open a ticket in ✉│contact-staff!`)
  63.  
  64.         }
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement