A minimal, production-ready Discord bot template built with TypeScript and Discord.js v14. Designed to be "plug and play" with minimal setup required.
- 🔹 Dynamic command registration - Commands are automatically loaded from the commands directory
- 🔹 TypeScript support - Full type safety with proper type definitions
- 🔹 Advanced error handling - Comprehensive error handling with user-friendly messages
- 🔹 Flexible deployment - Guild-specific or global command deployment
- 🔹 Clean architecture - Modular, extensible codebase
- 🔹 Database integration - MongoDB support with connection pooling
- 🔹 Docker support - Ready for containerized deployment
- 🔹 Setup automation - Interactive setup script for easy configuration
# Clone the repository
git clone <your-repo-url>
cd discord-bot-template
# Install dependencies
npm install
# Run the interactive setup
npm run setup
# Start the bot
npm start
# Install dependencies
npm install
# Copy environment template
cp .env.example .env
# Edit .env with your configuration
# Then start the bot
npm start
# Using Docker Compose (includes MongoDB)
docker-compose up -d
# Or build and run manually
docker build -t discord-bot .
docker run -d --env-file .env discord-bot
src/
├── Bot.ts # Main bot class
├── main.ts # Entry point
├── config/ # Configuration system
│ └── index.ts
├── commands/ # Command files
│ └── ping.ts # Basic ping command
├── types/ # TypeScript type definitions
│ └── index.ts
└── utils/ # Utility functions
├── database.ts # Database connection
└── loadCommands.ts # Command loader
scripts/
└── setup.js # Interactive setup script
docs/ # Documentation
├── SYNC_COMMAND_README.md
└── USER_TRACKING_README.md
data/ # Runtime data (gitignored)
└── logs/ # Log files
Commands are automatically loaded from the src/commands/
directory. Here's how to create a new command:
import { SlashCommandBuilder } from 'discord.js';
import type { Command } from '../types';
export const myCommand: Command = {
data: new SlashCommandBuilder()
.setName('mycommand')
.setDescription('My awesome command!'),
async execute(interaction) {
await interaction.reply('🔹 Hello from my command!');
}
};
npm run dev
npm run build
npm run clean
BOT_TOKEN
(required): Your Discord bot tokenGUILD_ID
(optional): Guild ID for testing commands locallyMONGO_URI
(optional): MongoDB connection string for database features
- Go to Discord Developer Portal
- Create a new application
- Go to "Bot" section and create a bot
- Copy the token and add it to your
.env
file - In "OAuth2" > "URL Generator", select "bot" and "applications.commands" scopes
- Select necessary permissions and use the generated URL to invite your bot
- Sync Commands - Database synchronization features
- User Tracking - User and message tracking system
MIT