diff --git a/youmubot-core/src/community/mod.rs b/youmubot-core/src/community/mod.rs index 54b5e47..e554cee 100644 --- a/youmubot-core/src/community/mod.rs +++ b/youmubot-core/src/community/mod.rs @@ -67,25 +67,16 @@ pub async fn choose(ctx: &Context, m: &Message, mut args: Args) -> CommandResult .collect::>() .filter_map(|member| async move { // Filter by role if provided - if let Some(role) = role { - if member - .roles(&ctx) - .await - .map(|roles| roles.into_iter().any(|r| role == r.id)) - .unwrap_or(false) - { - Some(member) - } else { - None - } - } else { - Some(member) + match role { + Some(role) if member.roles.iter().any(|r| role == *r) => Some(member), + None => Some(member), + _ => None, } }) .collect() .await) } else { - panic!() + unreachable!() } }; let users = users?; diff --git a/youmubot-core/src/community/roles.rs b/youmubot-core/src/community/roles.rs index 93a75aa..c04fbca 100644 --- a/youmubot-core/src/community/roles.rs +++ b/youmubot-core/src/community/roles.rs @@ -118,8 +118,8 @@ async fn list(ctx: &Context, m: &Message, _: Args) -> CommandResult { async fn toggle(ctx: &Context, m: &Message, mut args: Args) -> CommandResult { let role = args.single_quoted::()?; let guild_id = m.guild_id.unwrap(); - let roles = guild_id.to_partial_guild(&ctx).await?.roles; - let role = role_from_string(&role, &roles); + let guild = guild_id.to_partial_guild(&ctx).await?; + let role = role_from_string(&role, &guild.roles); match role { None => { m.reply(&ctx, "No such role exists").await?; @@ -134,7 +134,7 @@ async fn toggle(ctx: &Context, m: &Message, mut args: Args) -> CommandResult { m.reply(&ctx, "This role is not self-assignable. Check the `listroles` command to see which role can be assigned.").await?; } Some(role) => { - let mut member = m.member(&ctx).await.unwrap(); + let mut member = guild.member(&ctx, m.author.id).await.unwrap(); if member.roles.contains(&role.id) { member.remove_role(&ctx, &role).await?; m.reply(&ctx, format!("Role `{}` has been removed.", role.name)) diff --git a/youmubot/src/main.rs b/youmubot/src/main.rs index 1fe939e..d1a008b 100644 --- a/youmubot/src/main.rs +++ b/youmubot/src/main.rs @@ -94,6 +94,8 @@ async fn main() { | GatewayIntents::GUILD_BANS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::GUILD_MESSAGE_REACTIONS + | GatewayIntents::GUILD_PRESENCES + | GatewayIntents::GUILD_MEMBERS | GatewayIntents::DIRECT_MESSAGES | GatewayIntents::DIRECT_MESSAGE_REACTIONS, )