shuttle
shuttle copied to clipboard
Add serenity as a service for building Discord bots
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)
}
}
Seconding this, would love to see this added!