Fix panic when setting volume after song ends

This commit is contained in:
Alex Page 2022-01-20 21:48:19 -05:00
parent 8d2e5dec41
commit 37885e5572

View file

@ -174,11 +174,11 @@ pub async fn set_volume(ctx: &mut Context, command: &ApplicationCommandInteracti
let current_track = data.get::<CurrentlyPlayingTrack>().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()
}
}