shuttle icon indicating copy to clipboard operation
shuttle copied to clipboard

Add serenity as a service for building Discord bots

Open kaleidawave opened this issue 2 years ago • 1 comments

Serenity is a framework for building Discord bots. Implementing Service for it under a flag would make it possible to host discord bots on Shuttle.

use serenity::Client;

#[shuttle_service::main]
async fn init() -> impl shuttle_service::SerenityService {
    let token = env::var("DISCORD_TOKEN").expect("token");
    let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT;

    let mut client = Client::builder(token, intents)
        .event_handler(...)
        .framework(...)
        .await
        .expect("Error creating client");

    Ok(client)
}

This should be a simple addition Serenity's client has a simple start function which selects and connects to a free port via web sockets:

#[async_trait]
impl Service for serenity::client::Client {
    async fn bind(mut self: Box<Self>, _addr: SocketAddr) -> Result<(), error::Error> {
        self
            .start()
            .await
            .map_err(error::CustomError::new)
    }
}

kaleidawave avatar Jul 25 '22 14:07 kaleidawave

Seconding this, would love to see this added!

atsuzaki avatar Jul 25 '22 21:07 atsuzaki