discord-spams

Discord spam protection library written in TypeScript by the discord.ts community

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
discord-spams
201.3.0a year agoa year agoMinified + gzip package size for discord-spams in KB

Readme

<a href="https://discord-ts.js.org" target="_blank" rel="nofollow">
  <img src="https://discord-ts.js.org/discord-ts.svg" width="546" />
</a>

<a href="https://discord.gg/yHQY9fexH9"
  ><img
    src="https://img.shields.io/discord/874802018361950248?color=5865F2&logo=discord&logoColor=white"
    alt="Discord server"
/></a>
<a href="https://www.npmjs.com/package/discord-spams"
  ><img
    src="https://img.shields.io/npm/v/discord-spams.svg?maxAge=3600"
    alt="NPM version"
/></a>
<a href="https://www.npmjs.com/package/discord-spams"
  ><img
    src="https://img.shields.io/npm/dt/discord-spams.svg?maxAge=3600"
    alt="NPM downloads"
/></a>
<a href="https://www.paypal.me/vijayxmeena"
  ><img
    src="https://img.shields.io/badge/donate-paypal-F96854.svg"
    alt="paypal"
/></a>

<b> Create a discord bot with TypeScript and Decorators! </b>

📖 Introduction
If you are reading this, then you are a developer who has encountered discord spam personally or through your discord server. That's also my story. The library is simple and provides functions to detect spam.
The sole purpose of this library is to provide a global list to prevent spam in Discord. Therefore, we are asking you to contribute to our little project and submit a pull request to add a new type of spam message.
💻 Installation
Version 16.6.0 or newer of Node.js is required

npm install discord-spams
yarn add discord-spams
📟 Example
@Discord()
export class Spam {
  lastUpdate: number | null = null;

  @On("messageCreate")
  async handler([message]: ArgsOf<"messageCreate">): Promise<void> {
    if (!message.guild || !message.member || message.author.bot) {
      return;
    }

    // update master list every five minute, will not be updated if event is not called
    if (!this.lastUpdate || Date.now() - this.lastUpdate > 5 * 60 * 1000) {
      await SpamMeta.refreshMasterList();
      this.lastUpdate = Date.now();
    }

    if (SpamMeta.isSpam(message.content)) {
      // delete message, if bot have permissions
      await message.delete().catch(() => null);

      // mute member for 6 hours
      const isMuted = await message.member
        .disableCommunicationUntil(
          Date.now() + 6 * 60 * 60 * 1000,
          "Spam message detected"
        )
        .catch(() => null);

      if (isMuted) {
        message.channel.send(
          `:cold_face: Spam message detected, I have muted ${message.author} for 6 hours.`
        );
      } else {
        message.channel.send(
          `:cold_face: Spam message detected from ${message.author}, please allow me to mute members!`
        );
      }
    }
  }
}
🙋 FAQ

  1. How to deal with new spam messages and links?

In your bot, create a command that allows all users to report links. On the bot side, add that link to spam storage using SpamMeta.addLink("cars-dont-fly.com");.
Later, Please report on our repository so we can add it to the global list.
☎️ Need help?
Ask in discord server
Thank you
Show your support for discordx
by giving us a star on github.