33 breaking releases

new 0.45.0 May 13, 2024
0.43.0 Apr 2, 2024
0.42.0 Mar 18, 2024
0.35.2 Dec 21, 2023
0.13.0 Mar 27, 2023

#645 in Network programming

Download history 161/week @ 2024-01-24 92/week @ 2024-01-31 71/week @ 2024-02-07 302/week @ 2024-02-14 254/week @ 2024-02-21 428/week @ 2024-02-28 382/week @ 2024-03-06 904/week @ 2024-03-13 210/week @ 2024-03-20 398/week @ 2024-03-27 457/week @ 2024-04-03 180/week @ 2024-04-10 424/week @ 2024-04-17 314/week @ 2024-04-24 401/week @ 2024-05-01 302/week @ 2024-05-08

1,468 downloads per month
Used in natsuki

Apache-2.0

34KB
505 lines

Shuttle service integration for the Serenity Discord bot framework

Serenity 0.12 is used by default. Poise 0.6 is also supported.

Serenity 0.11 is supported by using these feature flags (native TLS also available):

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

Example

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())
}

Dependencies

~13–30MB
~497K SLoC