Add stop command

This commit is contained in:
Alex Page 2023-03-02 21:20:24 -05:00
parent 9242d39f98
commit 332e7d4aa9
2 changed files with 29 additions and 1 deletions

View file

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

View file

@ -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))
},