This project is a Sapphire-based Discord bot that records message, command, member, and voice activity for every guild it joins. Metrics are buffered in Redis, persisted with Prisma/PostgreSQL, and rendered into shareable image cards using @napi-rs/canvas.
- Node.js 20 LTS
- pnpm ≥ 8 (or your preferred package manager)
- PostgreSQL 14 or newer
- Redis 6 or newer
- A Discord application with a bot token and the required gateway intents enabled (Guild Members, Guilds, Message Content, etc.)
Clone the repository and install packages. If you are already inside the project folder you can skip the git clone step.
git clone https://github.com/your-org/discord-server-analytic.git
cd discord-server-analytic
pnpm installUse the same package manager for all remaining commands. For npm users replace pnpm with npm.
Create a .env file in the project root. The bot loads configuration through @skyra/env-utilities during boot.
DISCORD_TOKEN=your_discord_bot_token
OWNERS=123456789012345678,987654321098765432
DATABASE_URL=postgresql://user:password@localhost:5432/server_analytic?schema=public
REDIS_URL=redis://localhost:6379
# Only include this line if your Redis instance requires authentication
# REDIS_PASSWORD=your_redis_passwordNever commit this file; it contains sensitive credentials.
- Start PostgreSQL and Redis so they accept TCP connections.
- Create the database specified in
DATABASE_URLif it does not exist. - Apply Prisma migrations to initialise the schema and generate the Prisma client:
pnpm prisma migrate deployDuring active development you can instead run pnpm prisma migrate dev --name init to create new migration files as the schema changes.
pnpm watch:starttsc-watch recompiles the project and restarts the bot whenever you save changes. Slash commands are (bulk) registered on login.
Alternatively, build once and start:
pnpm devCompile TypeScript and launch the compiled output:
pnpm build
pnpm startEnsure the production host has the same environment variables and network access to PostgreSQL and Redis.
- Login failures – confirm
DISCORD_TOKENis correct and the bot has been invited with the intents specified above. - Database errors – verify
DATABASE_URL, ensure PostgreSQL is reachable, and re-runpnpm prisma migrate deployif migrations were missed. - Redis authentication issues – remove
REDIS_PASSWORDif unnecessary or supply the correct password. - Slash commands not visible – command registrations may take a few minutes to propagate after the first login.
This project is distributed under the MIT license. Refer to LICENSE for the full text.