Skip to content

Commit

Permalink
fix(moderation): don't fail when taken_roles is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Axelen123 committed Jan 4, 2023
1 parent 503e095 commit bf0c34e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/utils/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u64>().unwrap()))
.collect::<Vec<_>>();

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::<u64>().unwrap()))
.collect::<Vec<_>>(),
)
.await?;
}
member.remove_role(http, mute_role_id).await?;
}
Ok(())
Expand Down

0 comments on commit bf0c34e

Please sign in to comment.