Type Safety
Fully typed API with compile-time error catching. Rust's ownership system ensures memory safety and prevents common programming errors.
A type-safe, high-performance, and easy-to-use QQ Guild Bot framework for Rust
BotRS is an asynchronous framework for the Rust programming language designed for building QQ Guild bots. It provides the essential building blocks needed for creating interactive bot applications that can handle messages, manage guilds, and respond to various events in real-time.
At a high level, BotRS provides several major components:
When building a QQ Guild bot, you need a framework that can handle the complexity of real-time messaging, API interactions, and event processing. BotRS serves as the foundation that allows you to focus on your bot's logic rather than the underlying infrastructure.
The framework handles:
Here's a simple bot that responds to messages:
use botrs::{Client, Context, EventHandler, Intents, Message, Ready, Token};
struct MyBot;
#[async_trait::async_trait]
impl EventHandler for MyBot {
async fn ready(&self, _ctx: Context, ready: Ready) {
println!("Bot is ready! Logged in as: {}", ready.user.username);
}
async fn message_create(&self, ctx: Context, message: Message) {
if let Some(content) = &message.content {
if content == "!ping" {
let _ = message.reply(&ctx.api, &ctx.token, "Pong!").await;
}
}
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = Token::new("your_app_id", "your_secret");
let intents = Intents::default().with_public_guild_messages();
let mut client = Client::new(token, intents, MyBot, true)?;
client.start().await?;
Ok(())
}Ready to build your first QQ Guild bot with BotRS? Follow our comprehensive guide:
BotRS maintains API compatibility with the official Python botpy library, making migration straightforward for developers familiar with the Python ecosystem. The structured parameter system mirrors botpy's approach while adding Rust's type safety benefits.
Rust's type system prevents entire classes of bugs common in dynamic languages:
BotRS is open source software released under the MIT license. Contributions are welcome!