| Crates.io | disruption |
| lib.rs | disruption |
| version | 0.2.0 |
| created_at | 2023-10-14 08:58:26.937636+00 |
| updated_at | 2025-10-26 23:16:11.874512+00 |
| description | A light wrapper around the Discord API and gateway. |
| homepage | |
| repository | https://github.com/H1ghBre4k3r/disruption |
| max_upload_size | |
| id | 1003016 |
| size | 144,650 |
⚠️ Note: This library is still under heavy development and commits may (and will) contain breaking changes!
A featherweight, type-safe Discord API wrapper written in Rust. Disruption provides a simple, event-driven interface for building Discord bots with production-ready gateway resilience.
Handler trait for processing Discord eventsAdd Disruption to your Cargo.toml:
[dependencies]
disruption = "0.1.0"
tokio = { version = "1.47", features = ["full"] }
async-trait = "0.1"
use async_trait::async_trait;
use disruption::{Client, Handler, channel::Message};
struct MyBot;
#[async_trait]
impl Handler for MyBot {
async fn on_message(&mut self, message: Message) {
match message.content() {
"!ping" => {
message.reply("Pong!").await.unwrap();
}
_ => {}
}
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut handler = MyBot;
let mut client = Client::new(&mut handler, "YOUR_BOT_TOKEN");
client.connect().await?;
client.start().await
}
The Handler trait provides methods for all supported Discord events. All methods have default implementations, so you only need to implement the events you care about:
#[async_trait]
impl Handler for MyBot {
async fn on_message(&mut self, message: Message) {
println!("Message: {}", message.content());
}
async fn on_message_update(&mut self, message: MessageApiType) {
println!("Message edited: {}", message.content);
}
async fn on_message_delete(&mut self, message_id: String, channel_id: String, guild_id: Option<String>) {
println!("Message deleted: {}", message_id);
}
}
#[async_trait]
impl Handler for MyBot {
async fn on_guild_create(&mut self, guild: GuildApiType) {
println!("Joined guild: {} ({} members)",
guild.name,
guild.member_count.unwrap_or(0)
);
}
async fn on_guild_member_add(&mut self, guild_id: String, member: GuildMemberApiType) {
println!("New member joined: {}", member.user.username);
}
}
#[async_trait]
impl Handler for MyBot {
async fn on_interaction(&mut self, interaction: InteractionApiType) {
// Handle slash commands, button clicks, etc.
println!("Interaction received: {:?}", interaction.type_);
}
}
#[async_trait]
impl Handler for MyBot {
async fn on_message_reaction_add(
&mut self,
user_id: String,
channel_id: String,
message_id: String,
guild_id: Option<String>,
emoji: EmojiApiType,
) {
println!("Reaction added: {:?}", emoji.name);
}
}
Disruption currently implements 17 of 72 Discord gateway events (23.6% coverage):
See GATEWAY_ROADMAP.md for the full event implementation roadmap.
Disruption is organized into three crates:
disruption (Main Crate)The high-level API for building Discord bots. Provides the Client, Handler trait, and helper implementations for working with Discord entities.
disruption_gatewayLow-level WebSocket gateway connection management. Handles connection lifecycle, heartbeats, RESUME logic, and exponential backoff reconnection.
disruption_typesShared type definitions for the Discord API. Contains 180+ strongly-typed structures for all Discord entities (messages, channels, guilds, users, roles, etc.).
Run the included examples to see Disruption in action:
# Basic bot with message handling
cargo run --example basic
# Set your bot token first
export BOT_TOKEN="your_bot_token_here"
cargo run --example basic
Disruption includes production-ready gateway features:
These features ensure your bot maintains reliable connections even during network interruptions or Discord outages.
Disruption is under active development. Current status:
See PHASE_1_COMPLETE.md for detailed implementation notes.
Contributions are welcome! Please note that the API is unstable and may change significantly between versions.
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ in Rust