Socket
Socket
Sign inDemoInstall

@devraelfreeze/discordjs-antispam

Package Overview
Dependencies
34
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
unMuteTime10Time in minutes to wait until unmuting a user.
modLogsEnabledfalseWhether moderation logs are enabled.
modLogsChannelCHANNEL_IDID 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
wordsFilterobjectWhether to use words filter system
wordsFilter.enabledfalseWhether to use links filter system
wordsFilter.typeSanctionwarnThe type of sanction to apply when a member trigger the words filter system
Options Object NameDefault ValueDescription
linksFilterobjectWhether to use links filter system
linksFilter.enabledfalseWhether 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
linksFilter.typeSanctionwarnThe type of sanction to apply when a member trigger the links filter system
Options Object NameDefault ValueDescription
antispamFilterobjectWhether to use antispam filter system
enabledtrueEnable / Disable antispam filter system
thresholdsobjectThresholds Object (See below for Options Object)
maxDuplicatesobjectMaxDuplicates Object (See below for Options Object)
maxInterval3000Amount of time (ms) in which messages are considered spam.
maxDuplicatesInterval3000Amount of time (ms) in which duplicate messages are considered spam.
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.mute5Amount of messages sent in a row that will cause a mute.
thresholds.kick6Amount of messages sent in a row that will cause a kick.
thresholds.ban8Amount 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.mute5Amount of duplicate messages sent in a row that will trigger a mute.
maxDuplicates.kick6Amount of duplicate messages sent in a row that will trigger a kick.
maxDuplicates.ban8Amount 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} has been warned for reason: **{reason}**'Message that will be sent when someone is warned.
message.mute'@{user} has been muted for reason: **{reason}**'Message that will be sent when someone is muted.
message.kick'**{user_tag}** has been kicked for reason: **{reason}**'Message that will be sent when someone is kicked.
message.ban'**{user_tag}** has been banned for reason: **{reason}**'Message that will be sent when someone is banned.
message.logs'{@user} '({user_id})' has been **${action}** for **${reason}** !'Message logs system (with modLogs Channel & Enabled)
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} 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} 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} 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, {
    wordsFilter: {
        enabled: false,
        typeSanction: 'warn', // warn or mute or ban or kick
    },
    antispamFilter: {
        thresholds: {
            warn: 4,
            mute: 6,
            kick: 8,
            ban: 10
        },
        maxDuplicates: {
            warn: 4,
            mute: 6,
            kick: 8,
            ban: 10
        },
        maxInterval: 3000,
        maxDuplicatesInterval: 3000,
    },
    linksFilter: {
        enabled: false,
        globalLinksFilter: false,
        discordInviteLinksFilter: false,
        customLinksFilter: false,
        typeSanction: 'warn'
    },
    unMuteTime: 10,
    deleteMessagesAfterBanForPastDays: 1,
    verbose: true,
    debug: false,
    removeMessages: true
});

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) => {
    /** Add message in cache */
    await antiSpam.addMessagesCache(message); // You must do this if you want to use antispamFilter System
    await antiSpam.messageAntiSpam(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.addMessagesCache(message); // You must do this if you want to use antispamFilter System
    await antiSpam.addMessagesCache(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 in message
     * return : getBadWords = ['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
     * @param {string|Array<string>} word(s) - Words to add
     * @param {string} guild_id - ID of the guild
     * @returns {Promise<boolean>} 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
     * @param {string|Array<string>} word(s) - Words to remove
     * @param {string} guild_id - ID of the guild
     * @returns {Promise<boolean>} true if removed or false if not removed.
     */
    const removeWord = await antiSpam.removeWords('bad word', message.guild.id);
    /**
     * Get words list for a guild.
     * @param {string} guild_id - ID of the guild
     * @returns {Promise<Array<string>>} Array of words
     */
    const wordsList = await antiSpam.listWords(message.guild.id);
});

/** Declare & Use module with 'messageCreate' event */
client.on("messageCreate", async (message) => {
    const contain_words = await antiSpam.messageLinksFilter(message);
    if (conatin_words) {
        /** Message contain link(s) */
    } else {
        /** Message doesn't contain link(s) */
    }

    /**
     * Add link / links for a guild
     * @param {string|Array<string>} links - Links to add
     * @param {string} guild_id - ID of the guild
     * @returns {Promise<boolean>} true if added or false if not added
     */
    const addLink = await antiSpam.addLinks('https://discord.gg/123456789', message.guild.id);
    /**
     * Remove link / links for a guild
     * @param {string|Array<string>} links - Links to remove
     * @param {string} guild_id - ID of the guild
     * @returns {Promise<boolean>} true if removed or false if not removed.
     */
    const removeLink = await antiSpam.removeLinks('https://discord.gg/123456789', message.guild.id);
    /**
     * Get links list for a guild.
     * @param {string} guild_id - ID of the guild
     * @returns {Promise<Array<string>>} Array of links
     */
    const linksList = await antiSpam.listLinks(message.guild.id);
});

⏳ 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: Anti Discord Invites 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.
  • Add support of error event with errors messages system
  • 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 15 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