Advertisement
user096

ban.js

Jan 10th, 2021
75
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: "ban",
  6.         description: "Bans a user from the guild!",
  7.         usage: "[user/ID] [reason]",
  8.         category: "moderation",
  9.         accessableby: "Moderators",
  10.     },
  11.     run: async (bot, message, args) => {
  12.         const embedColor = '#FFFF00'; // color: yellow, change the hex for different color
  13.         const warningColor = '#ff0000';
  14.         const okColor = '#00ff00';
  15.         let banMember = message.mentions.members.first() || await bot.users.fetch(args[0])
  16.         let reason = args.slice(1).join(" ");
  17.  
  18.         // MESSAGES
  19.  
  20.             message.delete().catch(O_o => {});
  21.  
  22.        let bansUser = await message.guild.fetchBans(banMember);
  23.  
  24.         if(bansUser.size < 1) {
  25.  
  26.             if (!banMember) {
  27.                 let nopersonembed = new Discord.MessageEmbed()
  28.                     .setTitle("❌Error")
  29.                     .setDescription("Missing target user to ban")
  30.                     .addField("required:", "mentions/ID", false)
  31.                     .setColor(warningColor);
  32.                 return message.channel.send(nopersonembed).then(msg => msg.delete({timeout: 5000})).catch(O_o => {
  33.                 });
  34.             }
  35.  
  36.             if (message.author === banMember) {
  37.                 let sanctionyourselfembed = new Discord.MessageEmbed()
  38.                     .setTitle("❌Error")
  39.                     .setDescription(`You cannot ban yourself`)
  40.                     .addField("required:", "mentions/ID", false)
  41.                     .setColor(warningColor);
  42.                 return message.channel.send(sanctionyourselfembed).then(msg => msg.delete({timeout: 5000})).catch(O_o => {
  43.                 });
  44.  
  45.             }
  46.  
  47.             if (!reason) reason = "No reason given!"
  48.  
  49.             if (!message.member.permissions.has("BAN_MEMBERS")) {
  50.                 let nopermsembed = new Discord.MessageEmbed()
  51.                     .setTitle("❌Error")
  52.                     .setDescription("Missing BAN_MEMBERS permission (user)")
  53.                     .addField("required:", "BAN_MEMBERS permission", false)
  54.                     .setColor(warningColor);
  55.                 return message.channel.send(nopermsembed).then(msg => msg.delete({timeout: 5000})).catch(O_o => {
  56.                 });
  57.             }
  58.  
  59.             if (!message.guild.me.permissions.has("BAN_MEMBERS")) {
  60.                 let botnopermsembed = new Discord.MessageEmbed()
  61.                     .setTitle("❌Error")
  62.                     .setDescription("Missing BAN_MEMBERS permission (bot)")
  63.                     .addField("required:", "BAN_MEMBERS permission", false)
  64.                     .setColor(warningColor);
  65.                 return message.channel.send(botnopermsembed).then(msg => msg.delete({timeout: 5000})).catch(O_o => {
  66.                 });
  67.             }
  68.  
  69.             let banembed = new Discord.MessageEmbed()
  70.                 .setColor(embedColor)
  71.                 .setAuthor(message.author.username, message.author.avatarURL({
  72.                     format: 'png',
  73.                     dynamic: true,
  74.                     size: 1024
  75.                 }))
  76.                 .setTitle(`You've been banned in ${message.guild.name}`)
  77.                .addField('Banned by', message.author.tag)
  78.                .addField('Reason', reason)
  79.                .setTimestamp();
  80.            banMember.send(banembed).then(() =>
  81.                message.guild.ban(banMember, {days: 1, reason: reason})).catch(O_o => {
  82.            });
  83.  
  84.            let successfullyembed = new Discord.MessageEmbed()
  85.                .setTitle("✅Success")
  86.                .setDescription(`${banMember.user.tag} has been banned.`)
  87.                .setColor(okColor);
  88.  
  89.            await message.channel.send(successfullyembed).catch(O_o => {
  90.            });
  91.  
  92.            //modlogs
  93.            let doneembed = new Discord.MessageEmbed()
  94.                .setTitle(`Moderation: Ban`)
  95.                .setColor(embedColor)
  96.                .setDescription(`${banMember.user.tag} has been banned by ${message.author.tag} because of ${reason}`)
  97.            let sChannel = message.guild.channels.cache.find(c => c.name === "shame-stream")
  98.            sChannel.send(doneembed).catch(O_o => {
  99.            });
  100.        } else {
  101.            let bannedEmbed = new Discord.MessageEmbed()
  102.                .setTitle("❌Error")
  103.                .setDescription(("This person is already banned from this server!"))
  104.                .setColor(warningColor);
  105.            return message.channel.send(bannedEmbed)
  106.        }
  107.    }
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement