From dc856ea3fdf8c23158102476aa31b346df060b6e Mon Sep 17 00:00:00 2001 From: Alex Page Date: Thu, 25 Jan 2024 20:24:05 -0500 Subject: [PATCH] Use better error message when failing to get metadata --- src/commands.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 57a1c75..1f81380 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -99,7 +99,19 @@ pub async fn play( debug!("Trying to play: {}", url); let mut source: Input = YoutubeDl::new(ctx.data().http_client.clone(), url.clone()).into(); - let metadata = source.aux_metadata().await?; + let metadata = match source.aux_metadata().await { + Ok(metadata) => metadata, + Err(_) => { + response + .edit( + ctx, + CreateReply::default() + .content("I couldn't find that video. Sorry! Maybe check your URL."), + ) + .await?; + return Ok(()); + } + }; debug!("Playing: {:?}", metadata); let title = metadata.title.clone().unwrap_or(String::from("This video")); @@ -181,7 +193,19 @@ pub async fn queue( debug!("Trying to play: {}", url); let mut source: Input = YoutubeDl::new(ctx.data().http_client.clone(), url.clone()).into(); - let metadata = source.aux_metadata().await?; + let metadata = match source.aux_metadata().await { + Ok(metadata) => metadata, + Err(_) => { + response + .edit( + ctx, + CreateReply::default() + .content("I couldn't find that video. Sorry! Maybe check your URL."), + ) + .await?; + return Ok(()); + } + }; debug!("Playing: {:?}", metadata); let title = metadata.title.clone().unwrap_or(String::from("This video"));