Skip to content

Acstane/Discord-Bot-Template

Repository files navigation

-->

Discord Bot Template

A Discord bot template built with discordx and TypeScript.

Features

  • TypeScript - Write type-safe code
  • 🎯 Decorators - Use decorators for commands and events
  • 🔧 Hot Reload - Auto-reload commands during development
  • 📦 ESM - Use ES modules
  • 🐳 Docker - Containerized deployment
  • 🗄️ Database - Prisma ORM with PostgreSQL
  • 🛡️ Error Handling - Comprehensive error handling and anti-crash system
  • 📊 Error Logging - Optional Discord channel error reporting
  • 🧹 Biome - Fast linting, formatting, and import organization

Environment Variables

Create a .env file in the root directory with the following variables:

# Discord Bot Token
DISCORD_TOKEN=your_discord_bot_token_here

# Database URL (for Prisma)
DATABASE_URL="postgresql://username:password@localhost:5432/database_name"

# Error Log Channel ID (optional - for error reporting to Discord)
ERROR_LOG_CHANNEL_ID=123456789012345678

# Environment
NODE_ENV=development

Error Logging to Discord Channel

If you want errors to be reported to a specific Discord channel, set the ERROR_LOG_CHANNEL_ID environment variable in your .env file to the target channel's ID:

ERROR_LOG_CHANNEL_ID=123456789012345678

When this is set, any error handled by the bot will also be posted to that channel as an embed for monitoring.

Installation

# Install dependencies
yarn install

# Generate Prisma client
yarn prisma generate

# Run database migrations
yarn prisma migrate dev

Development

# Start development server with hot reload
yarn dev

# Watch for file changes
yarn watch

Production

# Build the project
yarn build

# Start production server
yarn start

Docker

# Build and run with Docker Compose
docker-compose up --build

Scripts

  • yarn dev - Start development server with hot reload
  • yarn watch - Watch for file changes
  • yarn build - Build the project
  • yarn start - Start production server
  • yarn lint - Run Biome linting
  • yarn lint:fix - Fix Biome linting errors
  • yarn format - Format code with Biome
  • yarn format:fix - Format and write changes
  • yarn biome:fix - Run both linting and formatting fixes

Project Structure

src/
├── commands/          # Slash commands
│   └── categories/    # Command categories
├── events/           # Discord events
├── utils/            # Utility functions
│   └── errorHandler.ts # Error handling system
├── bot.ts            # Bot configuration
├── main.ts           # Entry point
└── dev.ts            # Development entry point

Error Handling

The bot includes a comprehensive error handling system that:

  • Catches and logs all errors with context
  • Prevents crashes from unhandled exceptions
  • Provides user-friendly error messages
  • Supports optional Discord channel error reporting
  • Implements rate limiting to prevent spam
  • Handles database operation errors safely

Code Quality

This project uses Biome for code quality:

  • Fast linting - Built in Rust for speed
  • Formatting - Consistent code style
  • Import organization - Automatic import sorting
  • TypeScript support - Full TypeScript integration
  • Decorator support - Works with Discord.js decorators

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run yarn biome:fix to format and lint
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

You can support discordx by giving it a GitHub star.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •