Skip to content

Commit 7576679

Browse files
mAxYoLo01pre-commit-ci[bot]FayeDel
authored
feat: Added User.avatar_url() to get the resulting URL from a user (#515)
* feat: Added User.avatar_url() to get the resulting URL from a user * ci: correct from checks. * fix: Make the User.avatar_url a property * fix: remove useless import * fix: remove wrong headers Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: DeltaX <33706469+DeltaXWizard@users.noreply.github.com>
1 parent c2bafa3 commit 7576679

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

interactions/api/models/user.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,19 @@ def mention(self) -> str:
6363
:rtype: str
6464
"""
6565
return f"<@{self.id}>"
66+
67+
@property
68+
def avatar_url(self) -> str:
69+
"""
70+
Returns the URL of the user's avatar
71+
72+
:return: URL of the user's avatar.
73+
:rtype: str
74+
"""
75+
url = "https://cdn.discordapp.com/"
76+
if self.avatar:
77+
url += f"avatars/{int(self.id)}/{self.avatar}"
78+
url += ".gif" if self.avatar.startswith("a_") else ".png"
79+
else:
80+
url += f"embed/avatars/{int(self.discriminator) % 5}.png"
81+
return url

interactions/api/models/user.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ class User(DictSerializerMixin):
2323
def __init__(self, **kwargs): ...
2424
@property
2525
def mention(self) -> str: ...
26+
@property
27+
def avatar_url(self) -> str: ...

0 commit comments

Comments
 (0)