Skip to content

Commit

Permalink
fix: The application did not respond error message because of the s…
Browse files Browse the repository at this point in the history
…low yt-dlp fetching
  • Loading branch information
kinkard committed Oct 16, 2024
1 parent e7b0275 commit aa79957
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use poise::CreateReply;
use serenity::builder::{CreateEmbed, CreateMessage};
use smallvec::{smallvec, SmallVec};
use songbird::input::Input;
use tracing::{info, warn};
use tracing::info;

use crate::{track_info, Context};

Expand Down Expand Up @@ -85,6 +85,8 @@ pub(crate) async fn play(ctx: Context<'_>, query: String) -> Result<(), anyhow::
}
});

let _ = ctx.reply(format!("Processing {query}...")).await;

#[cfg(feature = "spotify")]
let spotify_tracks: Option<SmallVec<[(track_info::Metadata, Input); 1]>> = ctx
.data()
Expand Down Expand Up @@ -140,20 +142,14 @@ pub(crate) async fn play(ctx: Context<'_>, query: String) -> Result<(), anyhow::
let queue_info = form_currently_played(&vc.queue().current_queue()).await;
drop(vc);

if let Err(err) = ctx
.send(CreateReply::default().embed(queue_info.clone()))
.await
{
warn!("Failed to reply: {err}. Falling back to sending a message");

// Fallback to sending a message if embed failed
ctx.channel_id()
.send_message(
ctx.serenity_context(),
CreateMessage::default().embed(queue_info),
)
.await?;
}
// fetching track info from yt-dlp may take some time (youtube seems to slow down such requests),
// so instead of replying we send a message.
ctx.channel_id()
.send_message(
ctx.serenity_context(),
CreateMessage::default().embed(queue_info),
)
.await?;

Ok(())
}
Expand Down

0 comments on commit aa79957

Please sign in to comment.