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

feat: Added User.avatar_url() to get the resulting URL from a user #515

Merged
merged 5 commits into from Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions interactions/api/models/user.py
Expand Up @@ -63,3 +63,19 @@ def mention(self) -> str:
:rtype: str
"""
return f"<@{self.id}>"

@property
def avatar_url(self) -> str:
"""
Returns the URL of the user's avatar

:return: URL of the user's avatar.
:rtype: str
"""
url = "https://cdn.discordapp.com/"
if self.avatar:
url += f"avatars/{int(self.id)}/{self.avatar}"
url += ".gif" if self.avatar.startswith("a_") else ".png"
else:
url += f"embed/avatars/{int(self.discriminator) % 5}.png"
return url
2 changes: 2 additions & 0 deletions interactions/api/models/user.pyi
Expand Up @@ -23,3 +23,5 @@ class User(DictSerializerMixin):
def __init__(self, **kwargs): ...
@property
def mention(self) -> str: ...
@property
def avatar_url(self) -> str: ...