From bf0c34e1676c9a49b1705ec25c994a3ea47b4b31 Mon Sep 17 00:00:00 2001 From: Ax333l Date: Wed, 4 Jan 2023 14:54:52 +0100 Subject: [PATCH] fix(moderation): don't fail when taken_roles is empty --- src/utils/moderation.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/utils/moderation.rs b/src/utils/moderation.rs index ec4747d..7e8b0ad 100644 --- a/src/utils/moderation.rs +++ b/src/utils/moderation.rs @@ -93,18 +93,21 @@ pub fn queue_unmute_member( .await? .ok_or("User was not muted.")?; - let taken_roles = db_result - .taken_roles - .unwrap() - .into_iter() - .map(|r| RoleId::from(r.parse::().unwrap())) - .collect::>(); - - let http = &ctx.http; - // Update roles if they didn't leave the guild. if let Some(mut member) = ctx.cache.member(guild_id, user_id) { - member.add_roles(http, &taken_roles).await?; + let http = &ctx.http; + + if let Some(taken_roles) = db_result.taken_roles { + member + .add_roles( + http, + &taken_roles + .into_iter() + .map(|r| RoleId::from(r.parse::().unwrap())) + .collect::>(), + ) + .await?; + } member.remove_role(http, mute_role_id).await?; } Ok(())