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 网络编程
957每月下载量
用于 natsuki
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