user096

warn.js

Jan 1st, 2021
1,741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2.  
  3. module.exports = {
  4.     config: {
  5.         name: "warn",
  6.         description: "warns a member from this guild",
  7.         usage: "[user/ID] [reason]",
  8.         category: "moderation",
  9.         accessableby: "Moderators",
  10.     },
  11.     run: async (bot, message, args) => {
  12.         var embedColor = '#FFFF00' // color: yellow, change the hex for different color
  13.  
  14.         let mentioned = message.mentions.members.first() || message.guild.members.get(args[0]);
  15.         let reason = args.slice(1).join(' ') // .slice(1) removes the user mention, .join(' ') joins all the words in the message, instead of just sending 1 word
  16.  
  17.         // MESSAGES
  18.  
  19.         if (!mentioned) {
  20.             return message.channel.send("You did not select a user to warn");
  21.         }
  22.  
  23.  
  24.         if (!reason) reason = "No reason given!"
  25.  
  26.         if (!message.member.permissions.has("MANAGE_MESSAGES")) {
  27.             let nopermsembed = new Discord.RichEmbed()
  28.                 .setDescription(
  29.                     "You do not have permission to warn members"
  30.                 )
  31.                 .setColor(embedColor);
  32.             return message.channel.send(nopermsembed);
  33.         }
  34.  
  35.         if (!message.guild.me.permissions.has("MANAGE_MESSAGES")) {
  36.             let botnopermsembed = new Discord.RichEmbed()
  37.                 .setDescription(
  38.                     "Missing `MANAGE_MESSAGES` permission for bot."
  39.                 )
  40.                 .setColor(embedColor);
  41.             return message.channel.send(botnopermsembed);
  42.         }
  43.  
  44.         message.delete() //delete the command msg
  45.  
  46.         let warningEmbed = new Discord.RichEmbed() // Creates the embed that's DM'ed to the user when their warned!
  47.             .setColor(embedColor)
  48.             .setAuthor(message.author.username, message.author.avatarURL)
  49.             .setTitle(`You've been warned in ${message.guild.name}`)
  50.            .addField('Warned by', message.author.tag)
  51.            .addField('Reason', reason)
  52.            .setTimestamp();
  53.        mentioned.send(warningEmbed); // DMs the user the above embed!
  54.  
  55.        var warnSuccessfulEmbed = new Discord.RichEmbed() // Creates the embed thats returned to the person warning if its sent.
  56.            .setColor(embedColor)
  57.            .setTitle(`${mentioned.user.tag} has been warned`);
  58.        message.channel.send(warnSuccessfulEmbed); // Sends the warn successful embed
  59.  
  60.        let doneembed = new Discord.RichEmbed()
  61.            .setTitle(`Moderation: Warn`)
  62.            .setColor(embedColor)
  63.            .setDescription(`${mentioned.user.tag} has been warned by ${message.author.tag} because of ${reason}`)
  64.        let sChannel = message.guild.channels.find(c => c.name === "shame-stream")
  65.        sChannel.send(doneembed)
  66.        
  67.    }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment