From 37885e5572665abef1699f7e9fdaf848d6397468 Mon Sep 17 00:00:00 2001 From: Alex Page Date: Thu, 20 Jan 2022 21:48:19 -0500 Subject: [PATCH] Fix panic when setting volume after song ends --- src/commands.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 785f5ce..aec1f7b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -174,11 +174,11 @@ pub async fn set_volume(ctx: &mut Context, command: &ApplicationCommandInteracti let current_track = data.get::().unwrap(); if let Some(track) = current_track { - track.set_volume(new_volume).unwrap(); - format!("Setting volume to {}%.", volume) - } else { - "Nothing's currently playing and for some reason, something needs to be playing to set the volume.".to_string() + if track.set_volume(new_volume).is_ok() { + return format!("Setting volume to {}%.", volume); + } } + "Nothing's currently playing and for some reason, something needs to be playing to set the volume.".to_string() } pub async fn set_loop(ctx: &mut Context, command: &ApplicationCommandInteraction) -> String { @@ -203,13 +203,12 @@ pub async fn set_loop(ctx: &mut Context, command: &ApplicationCommandInteraction if let Some(track) = current_track { if loops { track.enable_loop().expect("Couldn't enable looping"); - return format!("Loopin'!"); + "Loopin'!".to_string() } else { track.disable_loop().expect("Couldn't disable looping"); - return format!("This is the last time this track will EVER be played."); + "This is the last time this track will EVER be played.".to_string() } } else { "I can't loop a song if there is no song to loop.".to_string() } } -