A simple discord anti spam node.js module to prevent spam on your discord server
Branch: master
Clone or download
Latest commit 0485847 Feb 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Update .gitignore Oct 22, 2018
LICENSE small pm fix Oct 22, 2018
README.md Requiered -> Required and another grammar fix Feb 22, 2019
anti_spam.js Undo half of the commit, my bad Dec 10, 2018
package.json Update package.json Dec 9, 2018

README.md

discord-anti-spam.js

A simple module with quick setup and different options to implement Anti-Spam system in your bot.

DISCLAMER: You can only setup 1 set of configuration per client. (That means that you can't configure settings for each server for now. You can only modify in which guild checker is run and in which checker is not run.)

Installation

To install this module type the following command in your console:

npm i discord-anti-spam

Example

Example of a basic bot handling spam messages using this module.

const Discord = require('discord.js');
const antispam = require('discord-anti-spam'); // Requiring this module.
const client = new Discord.Client();

client.on('ready', () => {
  // Module Configuration Constructor
   antispam(client, {
        warnBuffer: 3, // Maximum ammount of messages allowed to send in the interval time before getting warned.
        maxBuffer: 5, // Maximum amount of messages allowed to send in the interval time before getting banned.
        interval: 2000, // Amount of time in ms users can send the maxim amount of messages(maxBuffer) before getting banned. 
        warningMessage: "please stop spamming!", // Message users receive when warned. (message starts with '@User, ' so you only need to input continue of it.) 
        banMessage: "has been hit by ban hammer for spamming!", // Message sent in chat when user is banned. (message starts with '@User, ' so you only need to input continue of it.) 
        maxDuplicatesWarning: 7,// Maximum amount of duplicate messages a user can send in a timespan before getting warned.
        maxDuplicatesBan: 10, // Maximum amount of duplicate messages a user can send in a timespan before getting banned.
        deleteMessagesAfterBanForPastDays: 7, // Deletes the message history of the banned user in x days.
        exemptRoles: ["Moderator"], // Name of roles (case sensitive) that are exempt from spam filter.
        exemptUsers: ["MrAugu#9016"] // The Discord tags of the users (e.g: MrAugu#9016) (case sensitive) that are exempt from spam filter.
      });
      
  // Rest of your code
});

client.on('message', msg => {
  client.emit('checkMessage', msg); // This runs the filter on any message bot receives in any guilds.
  
  // Rest of your code
}

client.login('token');

The code above will allow users to send a maximum of 3 messages. It will allow a maximum of 5 messages to be sent in an interval of 2000 Milliseconds (2 Seconds in Milliseconds), if more bot attempts to ban the user. The users will be warned with message @User, please stop spamming!. If user gets banned others will be notified with message @User has been hit by ban hammer in for spamming!. Maximum number of duplicated messages before user gets warned is 7. Maximum number of duplicated messages before bot attempts to ban user is 10. If user gets banned, the bot will delete all messages from that user that have been sent in the past 7 days. The bot will ignore any people with a role named Moderator and bot will ignore people named MrAugu#9016.

Documentation

antispam(<Client>);

This will configure module to run on its default configuration.
<Client> - Variable that defines new Discord.Client()
antispam - Variable that defines require('discord-anti-spam')

client.emit('checkMessage', <Message>)

<Message> - Variable that defines the message itself. (client.on('message', async (msg) =>{}) in this situation msg is the variable.) This will basically send your message to module. In fact is REQUIERED for module to run.

antispam(client, {
        warnBuffer: 3,
        maxBuffer: 5,
        interval: 2000,
        warningMessage: "",
        banMessage: "",
        maxDuplicatesWarning: 7,
        maxDuplicatesBan: 10,
        deleteMessagesAfterBanForPastDays: 7,
        exemptRoles: [],
        exemptUsers: []
      });

antispam - Variable that defines require('discord-anti-spam')
<Client> - Required, Discord.Client
warnBuffer - Optional, Type: Integer
maxBuffer - Optional, Type: Integer
interval - Optional, Type: Integer
warningMessage - Optonal, Type: String, Minimum 5 Characters
banMessage - Optional, Type: String, Minimum 5 Characters
maxDuplicatesWarning - Optional, Type: Integer
maxDuplicatesBan - Optional, Type: Integer
deleteMessagesAfterBanForPastDays - Optional, Type: Integer
exemptRoles - Optional, Type: Array
exemptUsers- Optional, Type: Array

NOTE: The module will throw errors for assigning incorrect types to configuration values.

That's pretty much all. <3
If you have any issues, bugs or trouble setting the module up, feel free to open an issue on Github