From 3e4561367c1cce286b2d605d489fb22747037c4a Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Fri, 23 Oct 2026 02:44:20 +0200 Subject: [PATCH] only send role changes the member doesn't already have add_roles and remove_roles make one API call per role, and every role linked to any Galtinn group was removed from every user on every run. Co-Authored-By: Claude Opus 5.5 --- bot/src/cogs/galtinn.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bot/src/cogs/galtinn.py b/bot/src/cogs/galtinn.py index fe34966..479ea4e 100644 --- a/bot/src/cogs/galtinn.py +++ b/bot/src/cogs/galtinn.py @@ -485,6 +485,14 @@ class Galtinn(commands.Cog): self.bot.logger.error(f"Could not resolve Discord roles to add for user {user.id}: {missing_roles_to_add}") success = False + # Only touch roles that actually change. Discord needs one API call per role added or removed + current_roles = set(user.roles) + roles_to_add -= current_roles + roles_to_remove &= current_roles + + if not roles_to_add and not roles_to_remove: + return success + if unassignable_roles := {role for role in roles_to_add | roles_to_remove if not role.is_assignable()}: self.bot.logger.error( f"Discord bot cannot manage roles for user {user.id}: {[role.id for role in unassignable_roles]}. "