35个重大版本更新

0.47.0 2024年7月23日
0.45.0 2024年5月13日
0.42.0 2024年3月18日
0.35.2 2023年12月21日
0.13.0 2023年3月27日

#980 in 网络编程

Download history 401/week @ 2024-05-01 344/week @ 2024-05-08 262/week @ 2024-05-15 285/week @ 2024-05-22 397/week @ 2024-05-29 248/week @ 2024-06-05 345/week @ 2024-06-12 199/week @ 2024-06-19 165/week @ 2024-06-26 162/week @ 2024-07-03 659/week @ 2024-07-10 264/week @ 2024-07-17 323/week @ 2024-07-24 210/week @ 2024-07-31 198/week @ 2024-08-07 120/week @ 2024-08-14

957每月下载量
用于 natsuki

Apache-2.0

34KB
505

Serenity Discord机器人框架的Shuttle服务集成

默认使用Serenity 0.12。也支持Poise 0.6。

使用以下功能标志支持Serenity 0.11(也提供native TLS)

serenity = { version = "0.11.7", features = ["..."] }
shuttle-serenity = { version = "0.47.0", default-features = false, features = ["serenity-0-11-rustls_backend"] }

示例

use anyhow::Context as _;
use serenity::async_trait;
use serenity::model::channel::Message;
use serenity::model::gateway::Ready;
use serenity::prelude::*;
use shuttle_runtime::SecretStore;
use tracing::{error, info};

struct Bot;

#[async_trait]
impl EventHandler for Bot {
    async fn message(&self, ctx: Context, msg: Message) {
        if msg.content == "!hello" {
            if let Err(e) = msg.channel_id.say(&ctx.http, "world!").await {
                error!("Error sending message: {:?}", e);
            }
        }
    }

    async fn ready(&self, _: Context, ready: Ready) {
        info!("{} is connected!", ready.user.name);
    }
}

#[shuttle_runtime::main]
async fn serenity(
    #[shuttle_runtime::Secrets] secrets: SecretStore,
) -> shuttle_serenity::ShuttleSerenity {
    // Get the discord token set in `Secrets.toml`
    let token = secrets.get("DISCORD_TOKEN").context("'DISCORD_TOKEN' was not found")?;

    // Set gateway intents, which decides what events the bot will be notified about
    let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT;

    let client = Client::builder(&token, intents)
        .event_handler(Bot)
        .await
        .expect("Err creating client");

    Ok(client.into())
}

依赖项

~13–30MB
~506K SLoC