Advertisement
Guest User

Warn Command

a guest
Aug 29th, 2018
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js"); //gets the discord library
  2. const fs = require("fs");
  3. const ms = require("ms");
  4. let warns = JSON.parse(fs.readFileSync("./warnings.json", "utf8"));
  5.  
  6. module.exports.run = async (bot, message, args) => {
  7.   if(!message.member.hasPermission("MANAGE_MEMBERS")) return message.reply("You do not have permission");
  8.     let wUser = message.mentions.members.first()
  9.     if(!wUser) return message.reply("Counldn't find the member");
  10.     if(wUser.hasPermission("MANAGE_MESSAGES")) return message.reply("Cannot warn this member");
  11.   let reason = args.slice(1).join(" ");
  12.  
  13.   if(!warns[wUser.id]) warns[wUser.id] = {
  14.     warns: 0
  15.   };
  16.  
  17.   warns[wUser.id].warns++;
  18.  
  19.   fs.writeFile("./warnings.json", JSON.stringify(warns), (err) => {
  20.     if (err) console.log(err);
  21.   });
  22.  
  23.   //all works
  24.  
  25.   let warnEmbed = new Discord.RichEmbed()
  26.     .setDescription("Warns")
  27.     .setAuthor(message.author.username)
  28.     .setColor("#fc6400")
  29.     .addField("Warned User", `<@${wUser.id}>`)
  30.     .addField("Warned In", message.channel)
  31.     .addField("Number of Warnings", warns[wUser.id].warns)
  32.     .addField("Reason", reason);
  33.  
  34.   let warnchannel = message.guild.channels.find(c => c.name === "bot_logs");
  35.   if(!warnchannel) return message.reply("Couldn't find channel");
  36.  
  37.   warnchannel.send(warnEmbed);
  38.  
  39.   if(warns[wUser.id].warns == 2){
  40.     let muterole = message.guild.roles.find(c => c.name === "muted");
  41.     if(!muterole) return message.reply("Cannot find role");
  42.     let mutetime = "10s";
  43.     await(wUser.addRole(muterole.id));
  44.     message.channel.send(`<@${wUser.id}> has been temporarily muted`); //works with this but not channel.send
  45.     //works to here,aside from undefined user in the embed
  46.     setTimeout(function(){
  47.       wUser.removeRole(muterole.id)
  48.       message.reply(`<@${wUser.id}> has been unmuted`) //was message.channel.reply
  49.     }, ms(mutetime))
  50.  
  51.   }
  52.  
  53.   if(warns[wUser.id].warns == 3){
  54.     wUser.ban(reason)
  55.     message.reply(`<@${wUser.id}> has been banned`) //was message.channel.send
  56.   }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. //return message.channel.send("so far good");
  64. }
  65.  
  66. module.exports.help = {
  67.   name: "warn2"
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement