const authors = [];
var warned = [];
var banned = [];
var messagelog = [];

/**
 * Add simple spam protection to your discord server.
 * @param  {Bot} bot - The discord.js CLient/bot
 * @param  {object} options - Optional (Custom configuarion options)
 * @return {[type]}         [description]
 */
const Discord = require('discord.js');
module.exports = function (bot, options) {
  // Set options
  const warnBuffer = (options && options.prefix) || 7;
  const maxBuffer = (options && options.prefix) || 20;
  const interval = (options && options.interval) || 1000;
  const warningMessage = (options && options.warningMessage) || "stop spamming or I'll whack your head off.";
  const banMessage = (options && options.banMessage) || "has been banned for spamming, anyone else?";
  const maxDuplicatesWarning = (options && options.duplicates || 7);
  const maxDuplicatesBan = (options && options.duplicates || 20);

  bot.on('message', msg => {

const muteRole = bot.guilds.get(msg.guild.id).roles.find('name', `SendMessage`);
const modlog = bot.channels.find('name', 'mod-log');
  
  const embed = new Discord.RichEmbed()
  .setTimestamp()
  .setColor(0xf0000)
  .setTitle("User Auto Muted")
  .setThumbnail(`${msg.author.avatarURL}`)
  .setDescription(`\n`)
  .addField("Username:",`${msg.author} (${msg.author.username})`,true)
  .addField("Moderator:",`Pie Bot`, true)
  .addField("Reason:",`[Auto-Mute] Auto muted by system for spamming.`, false)
  .setFooter(`User: ${msg.author.username}`,`${msg.author.avatarURL}`);
    if(msg.author.id != bot.user.id){
      var now = Math.floor(Date.now());
      authors.push({
        "time": now,
        "author": msg.author.id
      });
      messagelog.push({
        "message": msg.content,
        "author": msg.author.id
      });

      // Check how many times the same message has been sent.
      var msgMatch = 0;
      for (var i = 0; i < messagelog.length; i++) {
        if (messagelog[i].message == msg.content && (messagelog[i].author == msg.author.id) && (msg.author.id !== bot.user.id)) {
          msgMatch++;
        }
      }
      // Check matched count
      if (msgMatch == maxDuplicatesWarning && !warned.includes(msg.author.id)) {
        warn(msg, msg.author.id);
      }
      if (msgMatch == maxDuplicatesBan && !banned.includes(msg.author.id)) {
        msg.guild.member(msg.author).removeRole(muteRole)
    bot.channels.get(modlog.id).send({embed}).catch(console.error);
     msg.channel.send({embed}).catch(console.error);
          msg.author.sendMessage({embed: {
color: 0xff0000,
title: "User Automuted Warning",
description: (`\nYou have been auto muted!\n`),
fields: [{
  name : "Username:",
  value : `${msg.author.username} (${msg.author})`,
  inline : true
},{
  name : "Moderator:",
  value :`Pie Bot`,
  inline : true
},{
  name : "Mute reason:",
  value : `[Auto-Mute] Auto muted by system for spamming. (1 day)`,
  inline : false
},{
  name : "If you believe that this was an error, please contact the moderator involved.",
  value : `Please avoid interacting with the server for the time being. However, if you have not been unmuted after the stated time, please contact the moderator immediately.`,
  inline : false
}]
  }})
      }

      matched = 0;

      for (var i = 0; i < authors.length; i++) {
        if (authors[i].time > now - interval) {
          matched++;
          if (matched == warnBuffer && !warned.includes(msg.author.id)) {
            warn(msg, msg.author.id);
          }
          else if (matched == maxBuffer) {
            if (!banned.includes(msg.author.id)) {
              ban(msg, msg.author.id);
            }
          }
        }
        else if (authors[i].time < now - interval) {
          authors.splice(i);
          warned.splice(warned.indexOf(authors[i]));
          banned.splice(warned.indexOf(authors[i]));
        }
        if (messagelog.length >= 200) {
          messagelog.shift();
        }
      }
    }
  });

  /**
   * Warn a user
   * @param  {Object} msg
   * @param  {string} userid userid
   */
  function warn(msg, userid) {
    warned.push(msg.author.id);
    msg.channel.send("Stop spamming, " + msg.author + " continuing to spam will subsequently lead into a mute.");
  }

  /**
   * Ban a user by the user id
   * @param  {Object} msg
   * @param  {string} userid userid
   * @return {boolean} True or False
   */

  }


@@ -1146,16 +1146,17 @@
 olor(0xf
+f
 0000)%0A  
@@ -2301,36 +2301,93 @@
 s(msg.author.id)
-)
+ && msg.guild.member(msg.author).roles.has(muteRole.id)) 
  %7B%0A
+%0A
         msg.guil

Update anti_spam.js