A production-ready Discord bot framework built with nyxx and MongoDB — slash commands, prefix commands, anti-crash, webhook logging, stream-based async, and a modular src/ architecture.
Features • Quick Start • Structure • API • SQL Edition • Ecosystem
Discord Handler Dart is a production-ready bot framework using nyxx ^6.9.0 with Dart SDK ^3.0.0. Built on Dart's stream-based async model, it provides a dual command system (slash + prefix), anti-crash protection, HTTP webhook logging, MongoDB persistence via mongo_dart, and per-command cooldowns.
- Dual Command System — Slash and prefix commands with automatic registration
- Stream-Based Async — Fully asynchronous with Dart streams and
Future/async/await - Anti-Crash System — Global error zone handling
- Webhook Logging — HTTP webhook delivery via
httppackage for errors and guild events - MongoDB Integration —
mongo_dart ^0.10.0for persistent data storage - Cooldown System — Per-command cooldown management
- Environment Configuration —
dotenv ^4.2.0for secure config - Pub.dev Ecosystem — Lightweight dependency footprint
# Clone the repository
git clone https://github.com/RealMtrx/Discord-Handler-Dart.git
cd Discord-Handler-Dart
# Install dependencies
dart pub get
# Configure environment
cp .env.example .env
# Edit .env with your bot token, MongoDB URI, and webhook URLs
# Run the bot
dart runTOKEN=your_bot_token
PREFIX=!
BOT_NAME=Discord Handler
MONGO_URI=mongodb://localhost:27017/discord-handler
ERROR_WEBHOOK=https://discord.com/api/webhooks/...
GUILD_LOG_WEBHOOK=https://discord.com/api/webhooks/...Discord-Handler-Dart/
├── pubspec.yaml # Dart project config (nyxx ^6.9.0, mongo_dart)
├── src/
│ ├── main.dart # Entry point — initializes bot and starts listener
│ ├── config/Config.dart # .env configuration parser
│ ├── Core/
│ │ ├── command_utils.dart # Cooldown map & utility methods
│ │ ├── emojis.dart # Centralized emoji constants
│ │ └── webhook_util.dart # Webhook HTTP sender
│ ├── Database/
│ │ └── mongo.dart # MongoDB client setup (mongo_dart)
│ ├── Events/
│ │ ├── guild_create.dart # onGuildJoin
│ │ ├── guild_delete.dart # onGuildLeave
│ │ ├── interaction_create.dart # Slash command dispatcher
│ │ ├── message_create.dart # Prefix command dispatcher
│ │ └── ready.dart # onReady
│ ├── Handlers/
│ │ ├── anti_crash.dart # Global error zone handler
│ │ └── logger.dart # Console logging utilities
│ ├── Models/
│ │ └── user_model.dart # MongoDB user document model
│ └── Commands/
│ ├── Prefix/
│ │ └── ping.dart # Example prefix command
│ └── Slash/
│ └── ping.dart # Example slash command
// main.dart
import 'package:nyxx/nyxx.dart';
import 'config/Config.dart';
import 'handlers/anti_crash.dart';
void main() async {
final config = Config();
AntiCrash.setup();
final bot = NyxxFactory.createSnowflakeBot(config.token);
// Register event listeners
bot.onReady.listen((event) { /* onReady */ });
bot.onMessageCreate.listen((event) { /* prefix commands */ });
bot.onSlashCommandInteraction.listen((event) { /* slash commands */ });
await bot.connect();
}Create a file in src/Commands/Slash/<name>.dart:
import 'package:nyxx/nyxx.dart';
class SlashPing {
static const name = 'ping';
static const description = 'Replies with Pong!';
static Future<void> execute(ISlashCommandInteraction interaction) async {
await interaction.respond(MessageBuilder(content: 'Pong! 🏓'));
}
}Create a file in src/Commands/Prefix/<name>.dart:
import 'package:nyxx/nyxx.dart';
class PrefixPing {
static const name = 'ping';
static Future<void> execute(IMessage message) async {
await message.channel.sendMessage(MessageBuilder(content: 'Pong! 🏓'));
}
}Commands are auto-discovered at startup by scanning the Commands/ directory. Drop a new file in Commands/Slash/ or Commands/Prefix/ following the class convention, and the handler registers it automatically with no manual wiring required.
This repository uses MongoDB via mongo_dart. If you prefer a relational database, check out the SQL Edition:
The SQL edition replaces mongo.dart with drift ORM and uses SQLite as the default backend (with build_runner code generation).
The Discord Handler ecosystem spans 26 repositories across 13 programming languages — each with a MongoDB edition and a SQL (Sequelize) edition.
| Language | Repository |
|---|---|
| TypeScript | Discord-Handler-Ts |
| JavaScript | Discord-Handler-Js |
| Python | Discord-Handler-Py |
| Java | Discord-Handler-Java |
| Kotlin | Discord-Handler-Kt |
| C++ | Discord-Handler-Cpp |
| C# | Discord-Handler-Cs |
| Go | Discord-Handler-Go |
| Rust | Discord-Handler-Rs |
| Dart | Discord-Handler-Dart |
| PHP | Discord-Handler-Php |
| Ruby | Discord-Handler-Rb |
| Lua | Discord-Handler-Lua |
| Language | Repository |
|---|---|
| TypeScript | Discord-Handler-Ts-Sequelize |
| JavaScript | Discord-Handler-Js-Sequelize |
| Python | Discord-Handler-Py-Sequelize |
| Java | Discord-Handler-Java-Sequelize |
| Kotlin | Discord-Handler-Kt-Sequelize |
| C++ | Discord-Handler-Cpp-Sequelize |
| C# | Discord-Handler-Cs-Sequelize |
| Go | Discord-Handler-Go-Sequelize |
| Rust | Discord-Handler-Rs-Sequelize |
| Dart | Discord-Handler-Dart-Sequelize |
| PHP | Discord-Handler-Php-Sequelize |
| Ruby | Discord-Handler-Rb-Sequelize |
| Lua | Discord-Handler-Lua-Sequelize |
Hub repository: Discord-Handler — the multi-language overview and documentation hub.
This project is licensed under the MIT License — see the LICENSE file for details.
Built by Mtrx — Discord: 0hu2