Add stop command
This commit is contained in:
parent
9242d39f98
commit
332e7d4aa9
2 changed files with 29 additions and 1 deletions
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue