This example shows how to build a Poise bot with Shuttle that responds to the /hello command with world!.
useanyhow::Contextas _;usepoise::serenity_prelude::{ClientBuilder,GatewayIntents};useshuttle_runtime::SecretStore;useshuttle_serenity::ShuttleSerenity;structData{}// User data, which is stored and accessible in all command invocationstypeError=Box<dynstd::error::Error+Send+Sync>;typeContext<'a>=poise::Context<'a,Data,Error>;/// Responds with "world!"#[poise::command(slash_command)]asyncfnhello(ctx:Context<'_>)->Result<(),Error>{ ctx.say("world!").await?;Ok(())}#[shuttle_runtime::main]asyncfnmain(#[shuttle_runtime::Secrets] secret_store:SecretStore)->ShuttleSerenity{// Get the discord token set in `Secrets.toml`let discord_token = secret_store.get("DISCORD_TOKEN").context("'DISCORD_TOKEN' was not found")?;let framework =poise::Framework::builder().options(poise::FrameworkOptions{ commands:vec![hello()],..Default::default()}).setup(|ctx, _ready, framework|{Box::pin(asyncmove{poise::builtins::register_globally(ctx,&framework.options().commands).await?;Ok(Data{})})}).build();let client =ClientBuilder::new(discord_token,GatewayIntents::non_privileged()).framework(framework).await.map_err(shuttle_runtime::CustomError::new)?;Ok(client.into())}
If you want to explore other frameworks, we have more examples with popular ones like Tower and Warp. You can find them right here.
Be sure to check out the examples repo for many more examples!