Fix panic when setting volume after song ends
This commit is contained in:
parent
8d2e5dec41
commit
37885e5572
1 changed files with 6 additions and 7 deletions
|
@ -174,11 +174,11 @@ pub async fn set_volume(ctx: &mut Context, command: &ApplicationCommandInteracti
|
||||||
|
|
||||||
let current_track = data.get::<CurrentlyPlayingTrack>().unwrap();
|
let current_track = data.get::<CurrentlyPlayingTrack>().unwrap();
|
||||||
if let Some(track) = current_track {
|
if let Some(track) = current_track {
|
||||||
track.set_volume(new_volume).unwrap();
|
if track.set_volume(new_volume).is_ok() {
|
||||||
format!("Setting volume to {}%.", volume)
|
return 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()
|
|
||||||
}
|
}
|
||||||
|
"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 {
|
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 let Some(track) = current_track {
|
||||||
if loops {
|
if loops {
|
||||||
track.enable_loop().expect("Couldn't enable looping");
|
track.enable_loop().expect("Couldn't enable looping");
|
||||||
return format!("Loopin'!");
|
"Loopin'!".to_string()
|
||||||
} else {
|
} else {
|
||||||
track.disable_loop().expect("Couldn't disable looping");
|
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 {
|
} else {
|
||||||
"I can't loop a song if there is no song to loop.".to_string()
|
"I can't loop a song if there is no song to loop.".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue