Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Handler — Dart

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.

License Version 0.9.0 Beta Stars Issues Forks 26 Repos Discord


FeaturesQuick StartStructureAPISQL EditionEcosystem


Overview

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.

Features

  • 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 http package for errors and guild events
  • MongoDB Integrationmongo_dart ^0.10.0 for persistent data storage
  • Cooldown System — Per-command cooldown management
  • Environment Configurationdotenv ^4.2.0 for secure config
  • Pub.dev Ecosystem — Lightweight dependency footprint

Quick Start

# 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 run

Environment Variables

TOKEN=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/...

Project Structure

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

API Reference

Bot Initialization

// 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();
}

Creating Slash Commands

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! 🏓'));
  }
}

Creating Prefix Commands

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! 🏓'));
  }
}

Adding Commands

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.

Database Edition

This repository uses MongoDB via mongo_dart. If you prefer a relational database, check out the SQL Edition:

Discord-Handler-Dart-Sequelize

The SQL edition replaces mongo.dart with drift ORM and uses SQLite as the default backend (with build_runner code generation).

Related Repositories

The Discord Handler ecosystem spans 26 repositories across 13 programming languages — each with a MongoDB edition and a SQL (Sequelize) edition.

Core Framework (MongoDB)

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

Database Editions (SQL)

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.

License

This project is licensed under the MIT License — see the LICENSE file for details.


Built by Mtrx — Discord: 0hu2

Discord-Handler

About

Discord bot framework - Nyxx + MongoDB. Slash commands, prefix commands, anti-crash, webhook logging. Written in Dart.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages