Skip to content
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

[utils] Prevent is_staff from erroring if roles are None #496

Closed
wants to merge 2 commits into from
Closed
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: 4 additions & 3 deletions ballsdex/core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

def is_staff(interaction: discord.Interaction) -> bool:
if interaction.guild and interaction.guild.id in settings.admin_guild_ids:
roles = settings.admin_role_ids + settings.root_role_ids
if any(role.id in roles for role in interaction.user.roles): # type: ignore
return True
if isinstance(interaction.user, discord.Member):
Copy link
Member

Choose a reason for hiding this comment

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

This check isn't enough, from my understanding the issue is that roles returned by the API are None, if the base type of the user was discord.User to begin with, then the attribute roles wouldn't exist at all. I am pretty confident that all users we are dealing with are always discord.Member objects, so instead you need to filter out the items from member.roles that are empty

roles = settings.admin_role_ids + settings.root_role_ids
if any(role.id in roles for role in (interaction.user.roles or [])):
return True
return False


Expand Down
Loading