A Discord bot template built with discordx and TypeScript.
- ⚡ 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
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=developmentIf 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=123456789012345678When this is set, any error handled by the bot will also be posted to that channel as an embed for monitoring.
# Install dependencies
yarn install
# Generate Prisma client
yarn prisma generate
# Run database migrations
yarn prisma migrate dev# Start development server with hot reload
yarn dev
# Watch for file changes
yarn watch# Build the project
yarn build
# Start production server
yarn start# Build and run with Docker Compose
docker-compose up --buildyarn dev- Start development server with hot reloadyarn watch- Watch for file changesyarn build- Build the projectyarn start- Start production serveryarn lint- Run Biome lintingyarn lint:fix- Fix Biome linting errorsyarn format- Format code with Biomeyarn format:fix- Format and write changesyarn biome:fix- Run both linting and formatting fixes
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
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
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
- Fork the repository
- Create a feature branch
- Make your changes
- Run
yarn biome:fixto format and lint - Submit a pull request
MIT License - see LICENSE file for details.