Socket
Socket
Sign inDemoInstall

@devraelfreeze/discordjs-antispam

Package Overview
Dependencies
2
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @devraelfreeze/discordjs-antispam

Complex Antispam module for Discord JS


Version published
Maintainers
1
Created

Readme

Source

GitHub issues GitHub stars GitHub license npm
npm (tag)

❓ discordjs-antispam

A complex module with quick setup and different options to implement anti-spam and auto-moderation features in your bot.
This version of the package will only support discord.js v13

⚠️ This package support multi-guilds !

📥 Installation

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

npm i @devraelfreeze/discordjs-antispam

⚙️ AntiSpam Client Options

Options NameDefault ValueDescription
customGuildOptionsfalseWhether to use custom guild options
wordsFilterfalseWhether to use words filter system
maxInterval2000Amount of time (ms) in which messages are considered spam.
maxDuplicatesInterval2000Amount of time (ms) in which duplicate messages are considered spam.
unMuteTime10Time in minutes to wait until unmuting a user.
modLogsEnabledfalseWhether moderation logs are enabled.
modLogsChannelCHANNEL_IDName or ID of the channel in which moderation logs will be sent.
deleteMessagesAfterBanForPastDays1When a user is banned, their messages sent in the last x days will be deleted.
verbosefalseExtended logs from module (recommended).
debugfalseWhether to run the module in debug mode.
removeMessagestrueWhether to delete user messages after a sanction.
Options Object NameDefault ValueDescription
linksFilterobjectWhether to use links filter system
linksFilter.globalLinksFilterfalseWhether to filter global links (all links)
linksFilter.discordInviteLinksFilterfalseWhether to filter discord invite links
linksFilter.customLinksFilterfalseWhether to filter custom links per guild
Options Object NameDefault ValueDescription
thresholdsobjectAmount of messages sent in a row that will cause a warning / mute / kick / ban.
thresholds.warn4Amount of messages sent in a row that will cause a warning.
thresholds.mute6Amount of messages sent in a row that will cause a mute.
thresholds.kick8Amount of messages sent in a row that will cause a kick.
thresholds.ban10Amount of messages sent in a row that will cause a ban.
Options Object NameDefault ValueDescription
maxDuplicatesobjectAmount of duplicate messages that trigger a warning / mute / kick / ban.
maxDuplicates.warn4Amount of duplicate messages sent in a row that will trigger a warning.
maxDuplicates.mute6Amount of duplicate messages sent in a row that will trigger a mute.
maxDuplicates.kick8Amount of duplicate messages sent in a row that will trigger a kick.
maxDuplicates.ban10Amount of duplicate messages sent in a row that will trigger a ban
Options Object NameDefault ValueDescription
messageobjectMessages that will be sent when a sanction is applied.
message.warn'{@user}, Please stop spamming.'Message that will be sent when someone is warned.
message.mute'@{user} has been muted for spamming.'Message that will be sent when someone is muted.
message.kick'**{user_tag}** has been kicked for spamming.'Message that will be sent when someone is kicked.
message.ban'**{user_tag}** has been banned for spamming.'Message that will be sent when someone is banned.
Options Object NameDefault ValueDescription
errorMessageobjectWhether the bot should send a message when it doesn't have some required permissions
errorMessage.enabledtrueEnable / Disable the errorMessage system
errorMessage.mute'Could not mute **{user_tag}** because of improper permissions.'Message that will be sent when the bot doesn't have enough permissions to mute the member
errorMessage.kick'Could not kick **{user_tag}** because of improper permissions.'Message that will be sent when the bot doesn't have enough permissions to kick the member
errorMessage.ban'Could not ban **{user_tag}** because of improper permissions.'Message that will be sent when the bot doesn't have enough permissions to ban the member
Options Object NameDefault ValueDescription
ignoreobjectConfiguration of roles / members / channels / permissions to ignore
ignore.members[]Array of member IDs (or Function) that are ignored.
ignore.roles[]Array of role IDs or role names (or Function) that are ignored. Members with one of these roles will be ignored.
ignore.channels[]Array of channel IDs or channel names (or Function) that are ignored.
ignore.permissions[]Users with at least one of these permissions will be ignored.
ignore.botstrueWhether bots should be ignored.
Options Object NameDefault ValueDescription
enableobjectEnable / Disable sanction system
enable.warntrueWhether to enable warnings.
enable.mutetrueWhether to enable mutes.
enable.kicktrueWhether to enable kicks.
enable.bantrueWhether to enable bans.

⬇️ Examples

Example: Basic AntiSpam Client with Options

/** See all options above */
const AntiSpam = require("@devraelfreeze/discordjs-antispam");
const antiSpam = new AntiSpam(client, {
    customGuildOptions: true,
    wordsFilter: true,
    maxInterval: 2000,
    maxDuplicatesInterval: 2000,
    unMuteTime: 10,
    deleteMessagesAfterBanForPastDays: 1,
    verbose: false,
    debug: false,
    removeMessages: true,
    linksFilter: {
        globalLinksFilter: false,
        discordInviteLinksFilter: false,
        customLinksFilter: false
    },
    thresholds: {
        warn: 4,
        mute: 6,
        kick: 8,
        ban: 10
    },
    maxDuplicates: {
        warn: 4,
        mute: 6,
        kick: 8,
        ban: 10
    },
    message: {
        warn: "{@user}, Please stop spamming.",
        mute: "@{user} has been muted for spamming.",
        kick: "**{user_tag}** has been kicked for spamming.",
        ban: "**{user_tag}** has been banned for spamming."
    }
});

Example: Declare & Use module

const Discord = require("discord.js");
const client = new Discord.Client({
    intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES,
    Discord.Intents.FLAGS.GUILD_MEMBERS, Discord.Intents.FLAGS.GUILDS]
});
const AntiSpam = require("@devraelfreeze/discordjs-antispam");
const antiSpam = new AntiSpam(client, {
    /** Options of AntiSpam Client here */
});
client.on("ready", () => console.log(`Logged in as ${client.user.tag}.`));
client.on("messageCreate", async (message) => {
    await antiSpam.message(message);
});
/** Login the bot */
client.login("VERY SECRET TOKEN HERE :)");

Example: Declare & Use module with custom Guild Options

const Discord = require("discord.js");
const client = new Discord.Client({
    intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES,
        Discord.Intents.FLAGS.GUILD_MEMBERS, Discord.Intents.FLAGS.GUILDS]
});
const AntiSpam = require("@devraelfreeze/discordjs-antispam");
const antiSpam = new AntiSpam(client, {customGuildOptions: true});
client.on("ready", async () => {
    console.log(`Logged in as ${client.user.tag}.`)
    /** Custom guild options in Object */
    const guildId = "123456789012345678";
    const guildOptions = {/** Options of AntiSpam */};
    await antiSpam.setGuildOptions(guildId, guildOptions);
});
client.on("messageCreate", async (message) => {
    await antiSpam.message(message);
});
/** Login the bot */
client.login("VERY SECRET TOKEN HERE :)");

Example: Use Words Filter System (Functions)

/** Declare & Use module with 'messageCreate' event */
client.on("messageCreate", async (message) => {
    const contain_words = await antiSpam.messageWordsFilter(message);
    if (conatin_words) {
        /** Message contain word(s) */
    } else {
        /** Message doesn't contain word(s) */
    }
    
    /** Get array of bad words usages 
     * return : ['bad word', 'bad word', 'bad word']
     */
    const getBadWords = await antiSpam.messageBadWordsUsages(message);

    /**
     * Add custom word to the list for a guild
     * You can also use Array of words to add multiple words at once
     * e.g: antiSpam.addWords(['bad word', 'good word', 'bad word 2', 'good word 2'], message.guild.id);
     * return true if added or false if not added
     */
    const addWord = await antiSpam.addWords('bad word', message.guild.id);
    
    /**
     * Remove custom word from the list for a guild
     * You can also use Array of words to remove multiple words at once
     * e.g: antiSpam.removeWords(['bad word', 'good word', 'bad word 2', 'good word 2'], message.guild.id);
     * return true if removed or false if not removed.
     */
    const removeWord = await antiSpam.removeWords('bad word', message.guild.id);
});

/** Declare & Use module with 'messageCreate' event */

⏳ TODO

  • ✅ Add support of multi-guilds (Use Collection Cache)
  • ✅ Add and Test: Words Filter System (Can configure the words list to filter)
  • Add and Test: Discord Anti Links System
  • Add and Test: Anti Links System (Can configure links to filter)
  • Add and Test: Mass Mentions System
  • Add and Test: Emojis excessifs System
  • ✅ Bypass Bots for All Systems (Can be enabled or Disabled)
  • ✅ Complete ⚙️ AntiSpam Client Options
  • ✅ Find a method to clear cache for a guild when the cache is too big.
  • Create docs for the module

🐛 Bug Reports

If you have any bugs or trouble setting the module up, feel free to open an issue on Github Repository

If you want more support, you can contact me on Discord: Freeze#0123

🗃️ Old Versions

If you want to use old version, you can use command

npm i @devraelfreeze/discordjs-antispam@<version>

📝 License

Copyright © 2022 devRael1
This project is MIT licensed.
This is not an official Discord product. It is not affiliated with or endorsed by Discord Inc.

Keywords

FAQs

Last updated on 11 Jul 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc