A production-ready Discord bot framework built with Nyxx and drift — supports SQLite, PostgreSQL, and MySQL with a modular lib/ architecture.
Features • Quick Start • Structure • Database Config • API • MongoDB Edition • Ecosystem
An SQL edition of the Discord Handler framework built with Dart, Nyxx (Discord library), and drift (SQLite / PostgreSQL / MySQL ORM). It mirrors the architecture of the MongoDB edition, replacing document storage with relational database support while keeping the same modular structure, anti-crash protection, webhook logging, and dual command system.
- Dual Command System — Slash commands and prefix commands
- Event-Driven Architecture — Stream-based reactive design via Nyxx
- drift ORM — Type-safe SQL queries; supports SQLite, PostgreSQL, MySQL
- Anti-Crash Handler — Global error catching that keeps your bot online
- Webhook Error Logging — Real-time error and guild event reporting
- Cooldown System — Per-command rate limiting
- Emoji Constants — Centralized unicode emoji definitions
- Environment Configuration — Secure token management via
.env - Code Generation — drift
build_runnerfor type-safe DAOs
# Clone
git clone https://github.com/RealMtrx/Discord-Handler-Dart-Sequelize.git
cd Discord-Handler-Dart-Sequelize
# Configure
cp .env.example .env
# Edit .env with your bot token, client ID, and database details
# Install dependencies
dart pub get
# Generate drift code
dart run build_runner build
# Run the bot
dart run lib/main.dartlib/
├── main.dart # Entry point
├── bot.dart # Bot client initialization
├── config.dart # .env configuration loader
├── database/
│ ├── database.dart # Drift database definition
│ └── database.g.dart # Generated drift code
├── models/
│ └── user.dart # User model / table definition
├── handlers/
│ ├── anticrash.dart # Global error handler
│ ├── commands.dart # Slash command loader
│ ├── events.dart # Event loader
│ ├── logger.dart # Logging utility
│ └── prefix.dart # Prefix command handler
├── events/
│ ├── ready.dart # Bot ready event
│ ├── message_create.dart # Message create listener
│ ├── interaction_create.dart # Interaction create listener
│ ├── guild_create.dart # Guild create listener
│ └── guild_delete.dart # Guild delete listener
├── core/
│ ├── webhooks.dart # Webhook sender
│ ├── emojis.dart # Emoji constants
│ ├── command_utils.dart # Command helpers
│ └── cooldown.dart # Cooldown manager
└── commands/
├── slash/public/ping.dart # Example slash command
└── prefix/public/ping.dart # Example prefix command
Configure your database in .env:
# Bot
TOKEN=your_discord_bot_token
CLIENT_ID=your_client_id
OWNER_ID=your_user_id
PREFIX=!
# Database
DB_DIALECT=sqlite # sqlite | postgresql | mysql
DB_STORAGE=database.sqlite # SQLite file path (sqlite only)
# Webhooks
WEBHOOK_URL=
WEBHOOK_ID=
WEBHOOK_TOKEN=SQLite (default) — zero configuration, file-based:
DB_DIALECT=sqlite
DB_STORAGE=database.sqlitePostgreSQL:
DB_DIALECT=postgresql
DB_HOST=localhost
DB_PORT=5432
DB_NAME=discord_bot
DB_USER=postgres
DB_PASSWORD=your_passwordMySQL:
DB_DIALECT=mysql
DB_HOST=localhost
DB_PORT=3306
DB_NAME=discord_bot
DB_USER=root
DB_PASSWORD=your_passwordimport 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:sqlite3/sqlite3.dart';
import 'package:sqlite3/open.dart';
part 'database.g.dart';
class Users extends Table {
TextColumn get id => text()();
TextColumn get username => text()();
TextColumn get discriminator => text().nullable()();
TextColumn get avatar => text().nullable()();
DateTimeColumn get createdAt => dateTime()();
}
@DriftDatabase(tables: [Users])
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(_openConnection());
@override
int get schemaVersion => 1;
}
LazyDatabase _openConnection() {
return LazyDatabase(() async {
final file = File('database.sqlite');
return NativeDatabase(file);
});
}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!'));
}
}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!'));
}
}- Create a file in
lib/commands/slash/public/<name>.dartorlib/commands/prefix/public/<name>.dart - Define a class with
name,description(slash only), and a staticexecutemethod - The command loader automatically picks up new files
Prefer a document database? Use the MongoDB edition of this handler:
The MongoDB edition uses mongo_dart instead of drift, but shares the same command, event, and handler structure. You can switch between editions without relearning the architecture.
The Discord Handler ecosystem includes 26 repositories — 13 Core Framework (MongoDB) editions and 13 Database (SQL) editions, covering 13 programming languages.
| # | Language | Repository |
|---|---|---|
| 1 | JavaScript | Discord-Handler-Js |
| 2 | TypeScript | Discord-Handler-Ts |
| 3 | Go | Discord-Handler-Go |
| 4 | Rust | Discord-Handler-Rs |
| 5 | Python | Discord-Handler-Py |
| 6 | C# | Discord-Handler-Cs |
| 7 | Java | Discord-Handler-Java |
| 8 | Kotlin | Discord-Handler-Kt |
| 9 | C++ | Discord-Handler-Cpp |
| 10 | Dart | Discord-Handler-Dart |
| 11 | Ruby | Discord-Handler-Rb |
| 12 | Lua | Discord-Handler-Lua |
| 13 | PHP | Discord-Handler-Php |
| # | Language | Repository | ORM |
|---|---|---|---|
| 1 | JavaScript | Discord-Handler-Js-Sequelize | Sequelize |
| 2 | TypeScript | Discord-Handler-Ts-Sequelize | Sequelize |
| 3 | Go | Discord-Handler-Go-Sequelize | GORM |
| 4 | Rust | Discord-Handler-Rs-Sequelize | Diesel |
| 5 | Python | Discord-Handler-Py-Sequelize | SQLAlchemy |
| 6 | C# | Discord-Handler-Cs-Sequelize | EF Core |
| 7 | Java | Discord-Handler-Java-Sequelize | Hibernate |
| 8 | Kotlin | Discord-Handler-Kt-Sequelize | Exposed |
| 9 | C++ | Discord-Handler-Cpp-Sequelize | sqlpp11 |
| 10 | Dart | Discord-Handler-Dart-Sequelize | drift |
| 11 | Ruby | Discord-Handler-Rb-Sequelize | Sequel |
| 12 | Lua | Discord-Handler-Lua-Sequelize | LuaSQL |
| 13 | PHP | Discord-Handler-Php-Sequelize | Eloquent |
The hub repo contains documentation, examples in every language, changelog, roadmap, and contribution guidelines.
Distributed under the MIT License. See LICENSE for more information.
Built by Mtrx — Discord: 0hu2