Skip to content

fix(tty_roles.py): handle role assignment errors #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tux/cogs/services/tty_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ async def try_assign_role(member: discord.Member, role: discord.Role) -> None:
await discord.utils.sleep_until(datetime.datetime.now(datetime.UTC) + datetime.timedelta(seconds=5))
await member.add_roles(role)

except discord.NotFound as error:
# check if the member left the server
if member.guild.get_member(member.id) is None:
logger.info(f"Member {member} left or got kicked by the server before the role could be assigned.")
return
logger.error(f"Failed to assign role {role.name} to {member}: {error}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider lowering log level for expected NotFound errors

If a missing member is truly unexpected, keep the error level; otherwise (e.g. role deletion or race condition), switch to warning or debug to reduce log noise.


except Exception as error:
logger.error(f"Failed to assign role {role.name} to {member}: {error}")

Expand Down