Self-hosting the bot

(With screenshots!)

You can get a custom bot for free by self-hosting it, but keep in mind:

✅ Pros of Self-Hosting:

  • Full control over your data and customization.

  • No recurring subscription fees.

  • Can be deployed on your own infrastructure.

⚠️ Cons of Self-Hosting:

  • Requires technical expertise for setup and maintenance.

  • You are responsible for updates, security, and backups.

  • Hosting costs (servers, bandwidth, etc.) may apply.

  • If hosting on a personal computer, it must remain powered on 24/7 for the bot to be available at all times, which also increases electricity costs.

  • No official support beyond the provided setup instructions, or for specific additional software installation; self-troubleshooting is required.

For a hassle-free experience with automatic updates, security patches, and support, consider using our managed custom bots!

Recommendations

  • Have patience and read carefully this guide

  • Be familiarized with the CLI (cmd.exe, bash, zsh)

  • If you already know how to use the CLI and you still need help, feel free to ask in this discord server in #support

Creating a bot account

Go to the Discord Developer Portal, and click "New Application"

Discord Developer Portal Homepage

A dialog box will appear asking for a name. Type the name of your new bot and click "Create"

Create Application Dialog Box

Now let's configure your new Discord Bot

  1. Head over the Bot tab

  2. Enable the necessary privileged intents outlined, you can also upload the bot's icon and banner, or change its username

  3. Save the changes

  4. Click on "Reset Token", you will be prompted if you really want to proceed, click "Yes, do it!", the new token will be revealed, copy it and store it in a safe location

  5. Head over the OAuth2 tab

  6. Copy the client ID and store it in a safe location

  7. Click on "Reset Secret", you will be prompted if you really want to proceed, click "Yes, do it!", the new secret will be revealed, copy it and store it in a safe location

  8. Add another redirect URL

  9. Paste http://localhost:3000/api/auth/callback. You can change this to fit your needs

  10. Save the changes

Bot's Bot Tab
Bot's OAuth2 Tab

Install docker

Download and install Docker for your OS: https://docs.docker.com/engine/install/

Install git

Download and install git for your OS: https://git-scm.com/download

Install Member Counter

Open your terminal (cmd.exe, Terminal.app, etc) and run this command to download Member Counter

git clone --depth 1 --recurse-submodules --shallow-submodules -b master https://github.com/member-counter/bot.git

Now open the downloaded directory

cd bot

Configuring Member Counter

Open the bot folder in your terminal and create a .env file from the .env.example file

cp .env.example .env

A new .env file will appear in the folder, open it with your favorite text editor (like notepad.exe, vim, vscode, etc)

You might have to toggle the hidden files visibility in your file explorer to see this new file

macOS: ⇧ Shift + ⌘ Cmd + . while in Finder

Windows: Alt+V, then H, then H again, while in File Explorer

Linux: Ctrl+H, Alt+. in KDE

You will see a bunch of variables to set, but you only need to set the following block of variables at the start of the file:

  • COOKIE_SECRET: Choose some 32 character long password for encrypting session cookies

  • DISCORD_CLIENT_ID: Paste here your Discord Bot Client ID

  • DISCORD_CLIENT_SECRET: Paste here your Discord Bot Secret

  • DISCORD_BOT_INSTANCE_TOKEN: Paste your Discord Bot Token

  • DISCORD_OAUTH2_REDIRECT_URI: You will need to change this to allow using the website properly behind a reverse proxy or over other IP/hostname

Optional configuration

In order to use some additional counters, you must set the following variables:

  • YOUTUBE_API_KEY Paste here your YouTube API key, you can get it here

  • TWITCH_CLIENT_ID and TWITCH_CLIENT_SECRET Paste here your Twitch app credentials, you can get them here

  • MEMERATOR_API_KEY Paste here your Memerator API key, you can get it here, remember to check mark "Get Profiles - View Profiles."

Prepare the database

docker compose up -d --scale bot=0 --scale website=0

Apply database migrations

docker compose run -T db-utils npm run db:migrate up

Apply the database schema

docker compose run -T db-utils npm run db:push

Start Member Counter

Open again your terminal in the bot directory and use this command

docker compose up --attach website --attach bot

If you see a message like this, that means you have successfully installed Member Counter, else, it will give you errors that you must fix (stop the bot with Ctrl+C and check the previous steps)

website  |   ▲ Next.js 14.2.3
website  |   - Local:        http://localhost:3000
website  |   - Network:      http://0.0.0.0:3000
website  | 
website  |  ✓ Starting...
website  |  ✓ Ready in 212ms
bot      | info: Bot starting...
bot      | info: Bot ready
bot      | info: Logged in as Member Counter#1234
bot      | info: Invite link: https://discord.com/oauth2/authorize?client_id=1234567890&permissions=269569044&scope=bot
bot      | info: Requesting members
bot      | info: Sending bot stats...
bot      | info: Bot stats has been sent
bot      | info: Members received

If the bot is working well, let's make the bot auto start when your PC or server boots up, focus your terminal window and hit Ctrl+C to stop the bot and then run it again in the background with this:

docker-compose up -d

The bot will run in background, to stop it you can use

docker-compose down

Last updated