Expand description
Context module for Discord interaction handling.
This module provides the Context struct which is passed to event handlers
and provides convenient methods for responding to Discord interactions.
§Features
-
Automatic defer/reply handling: The context tracks whether you’ve already responded to an interaction and automatically uses the correct Discord API (initial response vs. edit).
-
Thread-safe: Uses
AtomicBoolfor response tracking, avoiding locks during async HTTP operations. -
JS/discord.py-like ergonomics: Methods like
reply(),reply_embed(),success(),error()for quick responses.
§Example
use titanium_rs::prelude::*;
async fn handle_command(ctx: Context) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// For long operations, defer first
ctx.defer(false).await?;
// Do some work...
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
// Then reply (automatically uses edit since we deferred)
ctx.reply("Done!").await?;
Ok(())
}Structs§
- Context
- Context for Discord interaction handling.