error handling invalid link

This commit is contained in:
Stachelbeere1248 2024-07-04 02:20:51 +02:00
parent c20fb2e827
commit d2d9894ff0
Signed by: Stachelbeere1248
SSH key fingerprint: SHA256:IozEKdw2dB8TZxkpPdMxcWSoWTIMwoLaCcZJ1AJnY2o
2 changed files with 7 additions and 3 deletions

View file

@ -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(())
}

View file

@ -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(())