diff --git a/src/commands.rs b/src/commands.rs index 274df57..dc97c14 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -119,3 +119,31 @@ pub async fn play( Ok(()) } + +#[poise::command(slash_command)] +pub async fn stop(ctx: CommandContext<'_>) -> Result<(), Error> { + let Some(guild) = ctx.guild() else { + ctx.say("You're not in a server, silly.").await?; + return Ok(()); + }; + + let manager = songbird::get(ctx.serenity_context()) + .await + .context("Expected a songbird manager")? + .clone(); + + if let Some(handler_lock) = manager.get(guild.id) { + let mut handler = handler_lock.lock().await; + handler.stop(); + { + let mut currently_playing = ctx.data().currently_playing.lock(); + *currently_playing = None; + } + ctx.say("Alright, I guess I'll stop.").await?; + } else { + ctx.say("I'm not even in a channel to begin with. Silly.") + .await?; + } + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index b8469b8..fffbb4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ async fn main() -> Result<()> { env::var("DISCORD_TOKEN").expect("Expected a bot token in the environment: DISCORD_TOKEN"); let options = poise::FrameworkOptions { - commands: vec![register(), join(), leave(), play()], + commands: vec![register(), join(), leave(), play(), stop()], event_handler: |ctx, event, framework, user_data| { Box::pin(event_event_handler(ctx, event, framework, user_data)) },