Crate titanium_rs

Crate titanium_rs 

Source
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 management
  • titanium-http: REST API client
  • titanium-model: Discord data models
  • titanium-cache: In-memory caching
  • titanium-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;

Modules§

client
Discord bot client implementation.
collector
context
Context module for Discord interaction handling.
error
framework
prelude