Skip to content

roselanesan/server_analytic

Repository files navigation

Discord Server Analytics Bot

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.

Prerequisites

  • 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.)

1. Install Dependencies

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 install

Use the same package manager for all remaining commands. For npm users replace pnpm with npm.

2. Provide Environment Variables

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_password

Never commit this file; it contains sensitive credentials.

3. Prepare Services

  1. Start PostgreSQL and Redis so they accept TCP connections.
  2. Create the database specified in DATABASE_URL if it does not exist.
  3. Apply Prisma migrations to initialise the schema and generate the Prisma client:
pnpm prisma migrate deploy

During active development you can instead run pnpm prisma migrate dev --name init to create new migration files as the schema changes.

4. Run the Bot

Development

pnpm watch:start

tsc-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 dev

Production

Compile TypeScript and launch the compiled output:

pnpm build
pnpm start

Ensure the production host has the same environment variables and network access to PostgreSQL and Redis.

Troubleshooting

  • Login failures – confirm DISCORD_TOKEN is correct and the bot has been invited with the intents specified above.
  • Database errors – verify DATABASE_URL, ensure PostgreSQL is reachable, and re-run pnpm prisma migrate deploy if migrations were missed.
  • Redis authentication issues – remove REDIS_PASSWORD if unnecessary or supply the correct password.
  • Slash commands not visible – command registrations may take a few minutes to propagate after the first login.

License

This project is distributed under the MIT license. Refer to LICENSE for the full text.

About

Monitor your Discord Server with advanced analytics and insights

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published