From c74c481d320626aeb940707dd5dd87381eaa278c Mon Sep 17 00:00:00 2001 From: jude Date: Tue, 25 Feb 2025 18:25:15 +0000 Subject: [PATCH] Fix soundboard interactions not working for switching play mode --- src/event_handlers.rs | 60 +++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/event_handlers.rs b/src/event_handlers.rs index 5c333bd..db479a6 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -96,11 +96,10 @@ pub async fn listener(ctx: &Context, event: &FullEvent, data: &Data) -> Result<( if let Some(guild_id) = component.guild_id { if let Ok(()) = SoundPager::handle_interaction(ctx, &data, component).await { } else { + component.defer(&ctx).await.unwrap(); let mode = component.data.custom_id.as_str(); match mode { "#stop" => { - component.defer(&ctx).await.unwrap(); - let songbird = songbird::get(ctx).await.unwrap(); let call_opt = songbird.get(guild_id); @@ -123,30 +122,37 @@ pub async fn listener(ctx: &Context, event: &FullEvent, data: &Data) -> Result<( ActionRowComponent::Button(button) => match &button .data { - ButtonKind::NonLink { custom_id, style } => row - .push( - CreateButton::new( - if custom_id.starts_with('#') { - custom_id.to_string() - } else { - format!( - "{}{}", - custom_id - .split('#') - .next() - .unwrap(), - mode - ) - }, - ) - .label(button.label.clone().unwrap()) - .emoji(button.emoji.clone().unwrap()) - .disabled( - custom_id == "#mode" - || custom_id == mode, - ) - .style(*style), - ), + ButtonKind::NonLink { custom_id, style } => { + let mut btn = CreateButton::new( + if custom_id.starts_with('#') { + custom_id.to_string() + } else { + format!( + "{}{}", + custom_id + .split('#') + .next() + .unwrap(), + mode + ) + }, + ) + .disabled( + custom_id == "#mode" + || custom_id == mode, + ) + .style(*style); + + if let Some(emoji) = button.emoji.clone() { + btn = btn.emoji(emoji); + } + + if let Some(label) = button.label.clone() { + btn = btn.label(label); + } + + row.push(btn) + } _ => {} }, _ => {} @@ -165,8 +171,6 @@ pub async fn listener(ctx: &Context, event: &FullEvent, data: &Data) -> Result<( } id_mode => { - component.defer(&ctx).await.unwrap(); - let mut it = id_mode.split('#'); let id = it.next().unwrap(); let mode = it.next().unwrap_or("instant");