Skip to content

Invite Tracker

by Bot-Hosting Node.js Social & Community Official

See who invited whom: join messages with the inviter, leaderboard, fake-invite detection and reward roles for invite goals.

Invite Tracker screenshot 1
Setup on Bot-Hosting

Know exactly who brings members to your server. The bot remembers every invite link and, when someone joins, credits the member who invited them. It also spots fake invites (brand-new accounts), counts members who left, and can hand out roles automatically when someone reaches an invite goal. Perfect for invite contests and growth campaigns.

What it does

  • Who invited whom: join and leave messages that name the inviter, including vanity URLs and single-use invites.
  • Leaderboard: /leaderboard ranks your best inviters, /invites shows anyone's stats (regular, left, fake, bonus).
  • Fake detection: accounts younger than a threshold you choose do not count.
  • Reward roles: give a role automatically at 5, 10, 50 invites...
  • Staff tools: add, remove or reset invites, and resync them.

1. Create the bot on Discord

  1. Open the Discord Developer Portal and click New Application.
  2. On General Information, copy the Application ID (CLIENT_ID).
  3. Go to Bot, click Reset Token and copy it (DISCORD_TOKEN).
  4. Still on Bot, turn on Server Members Intent.
  5. Go to OAuth2 > URL Generator, tick bot and applications.commands, give it Manage Server (to read invites), Manage Roles (for rewards), Send Messages and Embed Links, then add it to your server. Put the bot's role above the reward roles.

2. Deploy

Fill the variables and click Deploy. Set GUILD_ID to your server ID to get the commands instantly (global commands can take a few minutes).

3. Configure

  • /config channel: where join and leave messages go.
  • /config message: customize the join and leave texts.
  • /config fake-threshold: minimum account age (in days) for an invite to count.
  • /reward add: give a role at a number of invites.
  • /config view: check your settings. /help lists everything.

Good to know

  • Invites created before the bot joined are picked up when it starts, so add the bot before your campaign.
  • Data is saved in data/database.json with your files.
README.md

šŸŽÆ Discord Invite Tracker Bot

Discord.js v14 Node.js License: MIT PRs Welcome

An advanced, production-ready Discord Invite Tracker Bot built with Discord.js v14. It delivers real-time invite tracking, Discord Vanity URL detection, anti-alt account filters, automated milestone role rewards, interactive paginated leaderboards, and fully customizable join/leave embed logs.


✨ Key Features

  • ⚔ Real-Time Invite Caching Engine: Automatically captures and syncs invite uses across every guild without missing joins.
  • 🌐 Vanity URL & OAuth Detection: Seamlessly distinguishes between regular invites, server vanity URLs (discord.gg/vanity), and bot integrations.
  • šŸ›”ļø Anti-Alt / Fake Account Detection: Automatically calculates account creation age on join. Accounts younger than a configurable threshold (e.g. 3 days) are flagged as Fake and excluded from valid invite totals.
  • 🚪 Precise Member Departure Attribution: Tracks which user originally invited a departing member and automatically adjusts the inviter's stats (left + 1, regular - 1).
  • šŸŽ–ļø Automated Milestone Role Rewards: Set up reward milestones (e.g., 5 invites āž” Bronze, 10 invites āž” Silver). The bot awards roles instantly when goals are met.
  • šŸ† Interactive Paginated Leaderboard: Dynamic top 10 inviters display with gold, silver, and bronze badges (šŸ„‡ 🄈 šŸ„‰) and interactive button navigation (ā—€ļø Previous / Next ā–¶ļø).
  • šŸ“Š Detailed User Profile (/invites): View regular, left, fake, and bonus invites, win retention rate %, active invite codes, and a visual progress bar toward the next milestone.
  • šŸ“ Rich Template Interpolation: Customize welcome and leave messages with dynamic variables ({user}, {inviter}, {invites}, {total}, {guild.name}, {code}, {memberCount}).
  • šŸ’¾ Zero-Dependency Atomic Storage: Fast, persistent JSON database with in-memory caching and atomic temporary writes to eliminate race conditions and corrupted data.
  • šŸ›”ļø Slash Commands Only: Built exclusively with Discord Application (/) Slash Commands, compliant with modern Discord API standards.

šŸ“ø Preview & Showcase

+-----------------------------------------------------------+
| šŸ“Š Invite Statistics — Hashir                             |
| Detailed invite breakdown and tracking record.             |
|                                                           |
| šŸŽÆ Total Invites: 24 Invites                              |
| āœ… Regular: 26 members    | 🚪 Left: 3 departed           |
| šŸ¤– Fake/Alt: 1 flagged    | šŸŽ Bonus: +2 awarded          |
| šŸ“ˆ Retention Rate: 90% retained                           |
|                                                           |
| šŸŽ–ļø Milestone Progress                                     |
| Next Goal: @Gold Inviter (30 invites)                     |
| [▰▰▰▰▰▰▰▰▱▱] 80% (6 more needed)                        |
|                                                           |
| šŸ”— Active Invite Links                                    |
| • discord.gg/abcXYZ — 14 uses                             |
| • discord.gg/def123 — 12 uses                             |
+-----------------------------------------------------------+

šŸ“‹ Slash Commands Reference

šŸ“Š Member Commands

Command Description
/invites [user] View your own or another member's invite statistics, active codes, and milestone progress.
/leaderboard [page] View the server's top inviters with interactive pagination buttons.
/ping Check bot latency, Discord WebSocket heartbeat, memory usage, and uptime.
/help Display an interactive directory of all bot commands and template tags.

āš™ļø Server Configuration (Manage Guild Required)

Command Description
/config view Inspect current server channels, message templates, and anti-alt settings.
/config channel <type: join|leave> <channel> Set notification channels for member joins and leaves.
/config message <type: join|leave> <template> Set customized join or leave notification messages.
/config fake-threshold <days> Set the minimum account age (in days) to flag suspicious alt accounts.
/config embed-color <hex> Customize the bot's embed highlight color (e.g. #5865F2).

šŸŽ–ļø Role Rewards (Manage Roles Required)

Command Description
/reward add <invites> <role> Create or update a role reward granted when a member reaches an invite count.
/reward remove <role> Remove an existing role reward milestone.
/reward list Display all active role reward milestones configured on the server.

⚔ Administration (Administrator or Manage Guild Required)

Command Description
/add-invites <user> <amount> [reason] Award bonus invites to a member (e.g., for events, giveaways).
/remove-invites <user> <amount> [reason] Deduct invites from a member.
/reset-invites <user> Reset a member's invite record back to zero.
/sync-invites Force re-sync and rebuild all server invites into memory cache.

šŸ·ļø Message Template Variables

You can use the following placeholders inside /config message:

Placeholder Replaced With Example
{user} Mention of the joined/left user @Hashir
{user.tag} Username and tag of user Hashir#0001 or hashir
{user.id} Discord Snowflake ID of the user 987654321012345678
{inviter} Mention of the inviter (or Vanity / OAuth) @Alex
{inviter.tag} Tag of the inviter Alex#1234
{invites} / {total} Inviter's net total valid invites 15
{regular} Number of active members still in the server 18
{left} Number of invited members who departed 3
{fake} Number of invited accounts flagged as alts 1
{bonus} Admin-awarded bonus invites 2
{code} The specific invite code used xYz89P
{guild.name} Current server name Developers Hub
{memberCount} Current total server member count 1,248

šŸš€ Quick Setup & Installation

1. Prerequisites

2. Enable Privileged Gateway Intents

In the Discord Developer Portal:

  1. Select your Application āž” Bot tab.
  2. Scroll down to Privileged Gateway Intents.
  3. Enable Server Members Intent (GUILD_MEMBERS).
  4. Ensure the bot has permissions to:
    • Manage Server (to fetch server invites)
    • Manage Roles (to grant milestone role rewards)
    • Send Messages & Embed Links

3. Clone Repository & Install Dependencies

Bash
# Clone the repository
git clone https://github.com/hashiryahya/discord-invite-tracker.git

# Navigate to project directory
cd discord-invite-tracker

# Install required dependencies
npm install

4. Configure Environment Variables

Copy .env.example to .env:

Bash
cp .env.example .env

Open .env and fill in your credentials:

Env
DISCORD_TOKEN=your_bot_token_here
CLIENT_ID=your_application_client_id_here
GUILD_ID=your_test_guild_id_here   # Optional: For instant testing
DATABASE_PATH=./data/database.json

5. Register Slash Commands

Bash
npm run deploy-commands

6. Start the Bot

Bash
# Production mode
npm start

# Development mode (auto-reload on code change)
npm run dev

🐳 Docker Deployment

A Dockerfile is provided for containerized deployments:

Bash
# Build the Docker image
docker build -t discord-invite-tracker .

# Run the container
docker run -d --name invite-bot \
  -e DISCORD_TOKEN="your_token" \
  -e CLIENT_ID="your_client_id" \
  -v $(pwd)/data:/app/data \
  --restart unless-stopped \
  discord-invite-tracker

šŸ“ Project Architecture

discord-invite-tracker/
ā”œā”€ā”€ .env.example              # Environment variables template
ā”œā”€ā”€ .gitignore                # Git ignore patterns
ā”œā”€ā”€ Dockerfile                # Docker container configuration
ā”œā”€ā”€ LICENSE                   # MIT License
ā”œā”€ā”€ package.json              # NPM package manifest & scripts
ā”œā”€ā”€ README.md                 # Project documentation
ā”œā”€ā”€ data/
│   ā”œā”€ā”€ .gitkeep              # Git tracking placeholder
│   └── database.json         # Persistent JSON database (auto-generated)
└── src/
    ā”œā”€ā”€ config.js             # Configuration defaults loader
    ā”œā”€ā”€ deploy-commands.js    # Slash command registration script
    ā”œā”€ā”€ index.js              # Application entry point & client init
    ā”œā”€ā”€ commands/             # Slash commands organized by category
    │   ā”œā”€ā”€ admin/
    │   │   ā”œā”€ā”€ addInvites.js
    │   │   ā”œā”€ā”€ config.js
    │   │   ā”œā”€ā”€ removeInvites.js
    │   │   ā”œā”€ā”€ resetInvites.js
    │   │   ā”œā”€ā”€ reward.js
    │   │   └── syncInvites.js
    │   ā”œā”€ā”€ general/
    │   │   ā”œā”€ā”€ help.js
    │   │   └── ping.js
    │   └── invites/
    │       ā”œā”€ā”€ invites.js
    │       └── leaderboard.js
    ā”œā”€ā”€ database/
    │   └── db.js             # Atomic, thread-safe JSON database service
    ā”œā”€ā”€ events/               # Discord Gateway event handlers
    │   ā”œā”€ā”€ guildCreate.js
    │   ā”œā”€ā”€ guildDelete.js
    │   ā”œā”€ā”€ guildMemberAdd.js
    │   ā”œā”€ā”€ guildMemberRemove.js
    │   ā”œā”€ā”€ interactionCreate.js
    │   ā”œā”€ā”€ inviteCreate.js
    │   ā”œā”€ā”€ inviteDelete.js
    │   └── ready.js
    ā”œā”€ā”€ services/
    │   └── inviteTracker.js  # Real-time invite detection & caching engine
    └── utils/
        └── formatters.js     # Template parser, duration & embed helpers

šŸ¤ Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

  1. Fork the Project (git checkout -b feature/AmazingFeature)
  2. Commit your Changes (git commit -m 'Add some AmazingFeature')
  3. Push to the Branch (git push origin feature/AmazingFeature)
  4. Open a Pull Request

šŸ“„ License

Distributed under the MIT License. See LICENSE for more information.


šŸ‘Øā€šŸ’» Author

Hashir Yahya