For the complete documentation index, see llms.txt. This page is also available as Markdown.

Self-hosting the bot

Run your own copy of Member Counter with Docker, on your own machine or your own server.

A self-hosted bot is a copy of Member Counter that you run yourself. It logs in with your own Discord bot token and stores its data on your machine. It also serves its own dashboard at http://localhost:3000.

It has every feature: channels update every 5 minutes and every counter works, as long as you turn on the privileged intents in the Discord Developer Portal.

Self-hosting or a custom bot?

Self-hosting and a custom bot give you the same bot. The difference is who runs the machine.

Self-hosted bot
Custom bot

Free. You only pay for the hardware.

Paid, per quota unit per quarter.

You install, update and back it up.

We install, update and back it up.

Full control over your data and over every setting in .env.

Control panel with the settings that matter, on our hosting.

Runs as long as your machine is on.

Runs 24/7 on our infrastructure.

No official support beyond this guide.

Support from the team.

If you want the same result without the maintenance, read How to get a custom bot.

Requirements

You will type commands in a terminal. Read this guide top to bottom before you start: every step depends on the one above it.

Software
Notes

Docker, with Docker Compose v2.23.1 or newer

Install Docker. Check your version with docker compose version. Older versions cannot read the compose file.

A CPU with AVX support

The database runs mongo:7, and MongoDB 5.0 and newer need AVX. Older processors lack it, and some VMs and NAS boxes hide it from their guests. On Linux, check with grep -o avx /proc/cpuinfo | head -1.

1. Create your Discord application

Your bot needs its own application in the Discord Developer Portal. The steps are the same as for a custom bot:

Creating a Discord bot account

Come back with these four things:

  • the bot token

  • the client ID, on the OAuth2 tab

  • the client secret

  • a redirect URL added and saved on the OAuth2 tab: http://localhost:3000/api/auth/callback

2. Download Member Counter

Then open the folder it created:

-b master matters: the repository's default branch is dev, which runs beta images that break more often.

3. Create your .env file

Every setting lives in one file. Copy the example:

Open the new .env with any text editor. You might have to turn on hidden files in your file explorer to see it.

The variables you must fill in

The file starts with the block of variables you have to fill in yourself. Set these six:

Variable
What to put in it

COOKIE_SECRET

A random string of at least 32 characters. On macOS or Linux, openssl rand -base64 32 generates one. Shorter values are rejected on start-up.

DISCORD_CLIENT_ID

Your application's client ID.

DISCORD_CLIENT_SECRET

Your application's client secret.

DISCORD_BOT_INSTANCE_TOKEN

Your bot token.

WEBSITE_URL

Where you will open the dashboard. Leave http://localhost:3000 unless you put the bot behind a reverse proxy or a domain. Never add a trailing slash.

DISCORD_OAUTH2_REDIRECT_URI

Must match the redirect URL you saved in the Developer Portal character for character. Leave http://localhost:3000/api/auth/callback if you kept the default.

Two more you should change

These sit in the second block, the one marked as not needing changes. They have values already, but those defaults are written for the public bot.

Variable
Why it matters

PUBLIC_BOTS_IDS

Ships as '["main", "premium", "beta"]'. Your install runs a single bot with the id main, so the other two ids make your dashboard show two bots that are permanently offline. Set it to PUBLIC_BOTS_IDS='["main"]'.

MAIN_DISCORD_CLIENT_ID

Ships as 478567255198662656, the official Member Counter application. /invite builds its link from this value, so until you change it, /invite on your own bot invites ours. Set it to the same value as your DISCORD_CLIENT_ID.

Everything else already works for a single bot on one machine. For extra counters (YouTube, Twitch, Memerator, currency rates), a custom domain, a reverse proxy or sharding, see the configuration reference.

4. Prepare the database

Start only the database services:

setup-mongo-rs runs once and exits. Seeing it as Exited (0) in docker compose ps -a is the healthy outcome, not a failure.

Then create the collections and indexes, and apply the schema:

Both commands print their progress and exit.

5. Start the bot for the first time

Start everything, keeping the bot's and the backend's output on screen:

A healthy first start ends with these lines:

Keep the invite link for the next step. The warn line about OPENEXCHANGERATESORG_KEY is harmless.

On a cold start the bot and the backend can print database connection errors and restart a few times, because they start before MongoDB is ready and recover on their own.

If the log keeps failing, read the error and check the previous steps:

Error
Fix

Disallowed intents

Turn on both privileged intents in step 1.

Invalid token

Check DISCORD_BOT_INSTANCE_TOKEN.

Cookie secret too short

Make COOKIE_SECRET at least 32 characters.

When the log looks right, stop it with Ctrl + C and start it again in the background, so it survives closing the terminal:

6. Invite your bot and open the dashboard

Open the invite link from the log in a browser and add the bot to your server. The link already carries the permissions the bot needs.

Then open your dashboard at http://localhost:3000 and sign in with Discord.

The dashboard server picker after signing in with Discord
Your servers appear in the picker on the left

From here the bot works like any other install. Continue with Quick setup.

Day-to-day commands

Run all of these from the bot folder.

Command
What it does

docker compose ps

Shows which services are running.

docker compose logs -f bot

Follows the bot's log. Swap bot for backend, frontend or website.

docker compose restart bot

Restarts one service. It does not pick up .env changes; use docker compose up -d for that.

docker compose up -d

Starts everything in the background, and applies .env changes.

docker compose down

Stops and removes the containers.

Back up your data

Back up two things; everything else can be rebuilt:

  • storage/db holds your whole database: server settings, templates and channel settings.

  • .env holds your secrets and settings.

Run docker compose down before you copy storage/db, so you copy a database that nothing is writing to. To restore, put both back in place and run docker compose up -d. Redis is only a cache, so it needs no backup.

New versions ship as new container images. See Updating a self-hosted bot.

Getting help

Self-hosting is not covered by official support. Ask the community in #support on the support server. Bring the output of docker compose logs --tail 50 bot, and never paste your bot token. To report a bug or improve the bot itself, see How to contribute.

Technical details
  • The v2.23.1 floor comes from the inline configs: entry that carries the nginx configuration; older versions, including the standalone docker-compose v1, fail to parse it.

  • Branch and image tags: pushes to master build the :latest images, pushes to dev build the :beta images, and the compose file on each branch pins the matching tags. The git submodules are only needed to build the dashboard image yourself.

  • Update interval: the channel update job runs on the cron 0 */5 * * * * when the instance is premium and 0 */10 * * * * when it is not. DISCORD_BOT_INSTANCE_IS_PREMIUM ships as true.

  • Intents: GuildMembers and GuildPresences are requested only when DISCORD_BOT_INSTANCE_IS_PRIVILEGED and DISCORD_BOT_INSTANCE_IS_PREMIUM are both true, and GuildVoiceStates when the second is. With the portal toggles off, discord.js stops with Privileged intent provided is not enabled or whitelisted.

  • Every service validates .env on start-up, prints ❌ Invalid environment variables: with the failing keys and exits with Invalid environment variables, so a bad value shows up as a restart loop. COOKIE_SECRET signs the dashboard session cookies; WEBSITE_URL is the base URL and the allowed browser origin, which is why a trailing slash breaks it.

  • Invite link: permissions=269569044 is ViewChannel, ManageChannels, Connect, SendMessages, ReadMessageHistory, EmbedLinks, ManageRoles and BanMembers.

  • The deployCommands: lines on every start are normal: the bot registers its slash commands before logging in, because DISCORD_BOT_INSTANCE_DEPLOY_COMMANDS ships as true.

  • OPENEXCHANGERATESORG_KEY ships empty, so the log shows OPENEXCHANGERATESORG_KEY is not set, all rates will be x1 and every rate stays at 1. No counter uses it; it only affects currency conversion on the donors and donations pages. The optional counter keys are YOUTUBE_API_KEY, TWITCH_CLIENT_ID with TWITCH_CLIENT_SECRET, and MEMERATOR_API_KEY.

  • Log lines are timestamp - level - [meta] - message, and the bot's meta is [bot: <DISCORD_BOT_INSTANCE_ID> (<DISCORD_BOT_INSTANCE_CHILD_ID>)]. LOG_LEVEL takes error, warn, info (the default) or debug; set it in .env and run docker compose up -d again.

  • Database: mongo:7 runs with --replSet rs0 and the bind mount ./storage/db:/data/db; setup-mongo-rs runs rs.initiate with restart: "no" and is the only service that waits for MongoDB's healthcheck, which is why the bot and the backend can start first. db:migrate up runs mongo-migrate-ts and records what it applied in the migrations_changelog collection; db:push runs prisma db push.

  • Only website publishes a port, 3000:80. It is nginx:latest, configured from the inline compose config: it rewrites /api/(.*) to backend:8080/$1 and serves everything else from frontend. Behind another proxy, raise BACKEND_MAX_TRUSTED_PROXIES; its default 1 covers the bundled nginx only. rest-proxy and db-utils ship with deploy.replicas: 0, and the proxy only matters when several bot processes share one token: scale it to 1 and set DISCORD_BOT_INSTANCE_REST_PROXY_URL=http://rest-proxy:8765/api.

  • The dashboard image is a static build, so VITE_SUPPORT_URL, VITE_BOT_DOCS_URL, VITE_BOT_REPO_URL, VITE_TRANSLATION_PLATFORM_URL and SITE_URL are baked in when the image is built and editing them in .env changes nothing. VITE_SUPPORT_URL and VITE_BOT_REPO_URL must stay in .env anyway, because the bot requires them; SITE_URL ships commented out and is only read by the frontend build.

Last updated