Skip to content

A Discord Bot to protect your server from raids, spam, invitations, fake nitro ads and more written in C++

License

Notifications You must be signed in to change notification settings

Commandserver/Antispambot

Repository files navigation

Antispambot

Codacy Badge Lines of code GitHub

An efficient Discord Bot to prevent spam written in C++. Tested on a large discord server and mitigates around 90% of spam. Its well commented and therefor you can easily adapt it according to your needs.

Features

The following is considered as spam and will be deleted by the bot:

  • discord invitations
  • crossposted messages (repeated messages over too many channels). This also effects fake nitro ads!
  • repeated messages
  • messages with too many mentions
  • bad words (configurable in bad-words.txt)
  • messages that contains an url of a blacklisted domain (see domain-blacklist.txt)
  • forbidden file extensions like .exe (configurable in config.json)

The bot is using the new Timeout feature of Discord to time out users who spam! You can configure users and roles that are excluded.

🤖 It also detects raids when large amounts of users joined in a shorter time and notifies you.

🕐 All created threads will have a slow-mode of 3 seconds to prevent mass-pings in them.


The bot creates the following slash commands:

Slash command description
/manage To configurate excluded roles and users as well as managing the blacklisted domains and bad words.
/info Information about the bot
/massban Ban command to easily ban suspicious accounts
/masskick kick command to easily kick suspicious accounts

Dependencies

  • cmake (version 3.16+)
  • g++ (version 8 or higher)

Included dependencies (in the /libs folder)

Supported Platforms

I run the bot on Linux (ubuntu). But other UNIX-style platforms should build and run the bot fine.

Building

Compile instructions for Linux:

Go into the project directory and run the following commands.

mkdir build
cd build
cmake ..
make -j8

Replace the number after -j with a number suitable for your setup, usually the same as the number of cores on your machine.

Visit the D++ library documentation for more details.

Configuration and Running

Edit the config.json. The configuration variables in the file should be self-explanatory.

All bad words are saved line by line in the bad-words.txt.

The bypass-config.txt can be used to exclude users and roles from getting detected by the bot, just save the user- and role IDs line by line in it.

All forbidden domains are stored in domain-blacklist.txt. Used to prevent the sharing of certain websites/urls. You can also add top-level-domains to them.

The bot creates discord slash commands to manage the above three .txt-configs, therefor they're stored in extra files.

The bot requires the message content and server members intent to be enabled! Add the bot with the bot and applications.commands scope to your server! The bot needs at least the following permissions: VIEW_CHANNEL, SEND_MESSAGES, MANAGE_MESSAGES, MANAGE_THREADS, MODERATE_MEMBERS, BAN_MEMBERS, KICK_MEMBERS.


I'd recommend running the bot with systemd, to keep the bot always online.

A basic unit file could look like this:

[Unit]
Description=Antispam Discord Bot
After=network.target

[Service]
ExecStart=/home/PATH_TO_THE_EXECUTABLE
Type=simple
Restart=always

[Install]
WantedBy=multi-user.target

Support me

Be sure to leave a ⭐️ if you like the project :) Thank you! Be sure to contribute, if you're interested!

FAQ

Why C++?

I had pretty much the same bot in python, but I had problems with the message cache when it ran on a bigger discord server. Weird things happened and in the end i had no real control of the cache, so i moved to C++.