From d2d9894ff0d341e82bd73ab167dffd78b0ff1110 Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Thu, 4 Jul 2024 02:20:51 +0200 Subject: [PATCH] error handling invalid link --- src/commands/account.rs | 2 ++ src/handlers/bot_interaction.rs | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/commands/account.rs b/src/commands/account.rs index 3888e6f..777bc41 100644 --- a/src/commands/account.rs +++ b/src/commands/account.rs @@ -43,6 +43,8 @@ pub(crate) async fn add(ctx: Context<'_>, ign: String) -> Result<(), Error> { ])]) ).await?; ctx.send(CreateReply::default().content("Linked accounts.")).await?; + } else { + ctx.send(CreateReply::default().content("This Minecraft account's link doesn't seem to match your discord username. Be sure to not link using the display name and remove the @.")).await?; } Ok(()) } diff --git a/src/handlers/bot_interaction.rs b/src/handlers/bot_interaction.rs index 25eaba4..fd500c6 100644 --- a/src/handlers/bot_interaction.rs +++ b/src/handlers/bot_interaction.rs @@ -1,4 +1,4 @@ -use serenity::all::{ComponentInteraction, ComponentInteractionDataKind, Context, CreateMessage, GuildId, Interaction, RoleId}; +use serenity::all::{ComponentInteraction, ComponentInteractionDataKind, Context, CreateMessage, EditMessage, GuildId, Interaction, RoleId}; use crate::Error; pub(crate) async fn component(ctx: &Context, interaction: &Interaction) -> Result<(), Error>{ @@ -9,8 +9,8 @@ pub(crate) async fn component(ctx: &Context, interaction: &Interaction) -> Resul } } -async fn button(ctx: &Context, component: ComponentInteraction) -> Result<(), Error>{ - let m = component.message; +async fn button(ctx: &Context, mut component: ComponentInteraction) -> Result<(), Error>{ + let m = component.message.clone(); let u = m.mentions.first().expect("Message did not mention a user."); match component.data.custom_id.as_str() { "accept_verification" => { @@ -19,11 +19,13 @@ async fn button(ctx: &Context, component: ComponentInteraction) -> Result<(), Er let member = m.guild_id.unwrap_or(GuildId::new(1256217633959841853_u64)).member(ctx, u.id).await?; member.add_role(ctx, RoleId::new(1256218805911425066_u64)).await?; member.remove_role(ctx, RoleId::new(1256253358701023232_u64)).await?; + component.message.edit(ctx, EditMessage::new().components(vec![])).await?; Ok(()) }, "deny_verification" => { let _dm = u.direct_message(ctx, CreateMessage::new() .content("Your verified minecraft account was denied.")).await?; + component.message.edit(ctx, EditMessage::new().components(vec![])).await?; Ok(()) } _ => Ok(())