A production-ready Discord bot framework built with Discord.js v14 and MongoDB — slash commands, prefix commands, anti-crash, webhook logging, and a modular src/ architecture.
Features • Quick Start • Structure • API • SQL Edition • Ecosystem
Discord Handler JavaScript is a modular, production-ready Discord bot framework built on Discord.js v14 with MongoDB storage. It provides a complete foundation for building Discord bots with slash commands, prefix commands, event handling, anti-crash protection, and webhook-based logging — all organized in a clean, scalable src/ directory structure.
This is the reference implementation for the Discord Handler ecosystem. All 12 other language implementations follow the same architecture and patterns.
Version: 0.9.0 (Stable Beta) — Part of the Discord Handler ecosystem (26 repos across 13 languages).
- Dual Command System — Slash commands and prefix commands with auto-registration
- MongoDB Integration — Persistent data storage with Mongoose ODM
- Modular Architecture — Clean separation: Commands, Events, Handlers, Core, Database, Models
- Anti-Crash Protection — Handles
unhandledRejection,uncaughtException, andwarningevents - Webhook Logging — Dedicated webhooks for errors, slash commands, prefix commands, guild joins/leaves, and bot ready events
- Cooldown System — Per-command rate limiting with automatic periodic cleanup
- Dynamic Command Loading — Automatically discovers and registers commands from the filesystem
- Unicode Emoji System — Flat-export emoji constants for consistent rendering across platforms
- Environment Configuration — Secure token and secrets management via
dotenv - Startup Report — Color-coded terminal banner showing loaded commands, events, and connection status
- Graceful Shutdown — Proper cleanup on SIGINT and SIGTERM signals
# Clone the repository
git clone https://github.com/RealMtrx/Discord-Handler-Js.git
cd Discord-Handler-Js
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env with your bot token, client ID, and MongoDB URI
# Start the bot
npm start- Node.js 18+ — Runtime environment
- MongoDB — Local or Atlas instance
- Discord Application — Bot token and client ID from the Discord Developer Portal
Discord-Handler-Js/
├── package.json
├── .env.example
├── src/
│ ├── index.js # Entry point — initializes everything
│ ├── config.js # Configuration loader (env vars)
│ ├── Core/ # Shared utilities
│ │ ├── commandUtils.js # Cooldown, error formatting, logging
│ │ ├── emojis.js # Unicode emoji constants
│ │ ├── errorWebhook.js # Error reporting webhook
│ │ ├── joinGuildWebhook.js # Guild join notification webhook
│ │ ├── leaveGuildWebhook.js # Guild leave notification webhook
│ │ ├── prefixCommandWebhook.js
│ │ ├── readyWebhook.js # Bot ready event webhook
│ │ └── slashCommandWebhook.js
│ ├── Database/
│ │ └── mongo.js # MongoDB connection with Mongoose
│ ├── Events/ # Discord event listeners
│ │ ├── error.js
│ │ ├── guildCreate.js
│ │ ├── guildDelete.js
│ │ ├── interactionCreate.js
│ │ ├── messageCreate.js
│ │ └── ready.js
│ ├── Handlers/ # Loaders and registrars
│ │ ├── AntiCrash.js # Global error handlers
│ │ ├── Commands.js # Slash command loader and Discord API registration
│ │ ├── Events.js # Event file loader
│ │ ├── Models.js # Model file loader
│ │ ├── Prefix.js # Prefix command loader
│ │ └── logger.js # Startup report logger
│ ├── Models/
│ │ └── userModel.js # Mongoose User model
│ └── Commands/
│ ├── Slash/Public/ping.js
│ └── Prefix/Public/ping.js
| Function | Location | Description |
|---|---|---|
checkCooldown(userId, commandName, cooldownTime) |
Core/commandUtils.js |
Checks and sets per-command cooldowns |
logCommandUsage(user, commandName, guildName) |
Core/commandUtils.js |
Logs command usage (placeholder) |
formatError(error, commandName) |
Core/commandUtils.js |
Formats error objects for logging |
sendErrorToWebhook(error, context) |
Core/errorWebhook.js |
Sends error reports to Discord webhook |
sendBotReadyEvent(client) |
Core/readyWebhook.js |
Sends bot online notification |
sendGuildJoinEvent(guild, client) |
Core/joinGuildWebhook.js |
Sends guild join notification |
sendGuildLeaveEvent(guild, client) |
Core/leaveGuildWebhook.js |
Sends guild leave notification |
sendSlashCommandUsage(user, commandName, guildName) |
Core/slashCommandWebhook.js |
Logs slash command usage |
sendPrefixCommandUsage(user, commandName, guildName) |
Core/prefixCommandWebhook.js |
Logs prefix command usage |
| Function | Location | Description |
|---|---|---|
connectMongo() |
Database/mongo.js |
Connects to MongoDB via Mongoose |
| Function | Location | Description |
|---|---|---|
loadCommands(client) |
Handlers/Commands.js |
Scans Commands/Slash, imports, and registers with Discord API |
loadPrefix(client) |
Handlers/Prefix.js |
Scans Commands/Prefix and registers in-memory |
loadEvents(client) |
Handlers/Events.js |
Scans Events directory and attaches listeners |
loadModels() |
Handlers/Models.js |
Scans Models directory and imports each |
AntiCrash(client) |
Handlers/AntiCrash.js |
Attaches global process error handlers |
// src/Commands/Slash/Public/hello.js
import { SlashCommandBuilder } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('hello')
.setDescription('Say hello!'),
async execute(interaction) {
await interaction.reply('Hello! 👋');
}
};// src/Commands/Prefix/Public/hello.js
export default {
name: 'hello',
description: 'Say hello!',
async execute(client, message, args) {
await message.reply('Hello! 👋');
}
};This is the MongoDB edition. A SQL edition using Sequelize ORM is also available:
| Feature | MongoDB Edition | SQL Edition |
|---|---|---|
| Repository | Discord-Handler-Js | Discord-Handler-Js-Sequelize |
| Database | MongoDB | SQLite, PostgreSQL, MySQL, MSSQL |
| ORM | Mongoose | Sequelize |
| Dialects | MongoDB only | Multi-dialect via config |
Discord Handler JavaScript is part of a 26-repo ecosystem. Here are the other repositories:
| Language | Repository |
|---|---|
| TypeScript | Discord-Handler-Ts |
| Go | Discord-Handler-Go |
| Rust | Discord-Handler-Rs |
| Python | Discord-Handler-Py |
| C# | Discord-Handler-Cs |
| Java | Discord-Handler-Java |
| Kotlin | Discord-Handler-Kt |
| C++ | Discord-Handler-Cpp |
| Dart | Discord-Handler-Dart |
| Ruby | Discord-Handler-Rb |
| Lua | Discord-Handler-Lua |
| PHP | Discord-Handler-Php |
| Language | Repository |
|---|---|
| JavaScript | Discord-Handler-Js-Sequelize |
| TypeScript | Discord-Handler-Ts-Sequelize |
| Go | Discord-Handler-Go-Sequelize |
| Rust | Discord-Handler-Rs-Sequelize |
| Python | Discord-Handler-Py-Sequelize |
| C# | Discord-Handler-Cs-Sequelize |
| Java | Discord-Handler-Java-Sequelize |
| Kotlin | Discord-Handler-Kt-Sequelize |
| C++ | Discord-Handler-Cpp-Sequelize |
| Dart | Discord-Handler-Dart-Sequelize |
| Ruby | Discord-Handler-Rb-Sequelize |
| Lua | Discord-Handler-Lua-Sequelize |
| PHP | Discord-Handler-Php-Sequelize |
| Repository | Description |
|---|---|
| Discord-Handler | Central hub — documentation, examples, changelog, roadmap |
MIT License — Copyright © 2026 Mtrx
Discord Handler Ecosystem