Expand description
Titanium - The ultimate high-performance Discord API framework.
This crate provides a high-level wrapper around the Titanium ecosystem:
titanium-gateway: WebSocket connection managementtitanium-http: REST API clienttitanium-model: Discord data modelstitanium-cache: In-memory cachingtitanium-voice: Voice support
§Example
use titanium_rs::prelude::*;
use async_trait::async_trait;
struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn ready(&self, _: Context, ready: ReadyEventData<'_>) {
println!("Logged in as {}", ready.user.username);
}
async fn message_create(&self, ctx: Context, msg: Message<'_>) {
if &*msg.content == "!ping" {
let response = titanium_model::builder::MessageBuilder::new().content("Pong!").build();
if let Err(e) = ctx.http.create_message(msg.channel_id, &response).await {
eprintln!("Error sending message: {:?}", e);
}
}
}
}
#[tokio::main]
async fn main() {
let token = std::env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
let result = Client::builder(token)
.intents(Intents::GUILD_MESSAGES | Intents::MESSAGE_CONTENT)
.event_handler(Handler)
.build()
.await
.expect("Error creating client")
.start()
.await;
if let Err(why) = result {
eprintln!("Client error: {:?}", why);
}
}Re-exports§
pub use error::TitaniumError;pub use client::Client;pub use client::EventHandler;pub use framework::Framework;pub use titanium_cache as cache;pub use titanium_gateway as gateway;pub use titanium_http as http;pub use titanium_model as model;pub use titanium_voice as voice;