Skip to content

Commit 8860156

Browse files
committed
refactor: use discord.js avatarURL()
- Replaces manual avatar CDN URL construction with Discord.js's `avatarURL()` methods. - Defaults to optimized formats like webp instead of the previously hardcoded .png for non-animated avatars, which significantly reduced avatar size (e.g., from 24 KB to 1 KB).
1 parent eef9733 commit 8860156

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/lib/users.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,17 @@ module.exports.getPrivilegeLevel = async member => {
8282
module.exports.getAvatarData = member => {
8383
if (!member?.user) return false;
8484

85-
const cdnBaseUrl = 'https://cdn.discordapp.com';
86-
87-
const {
88-
id: userId,
89-
avatar: userAvatar,
90-
} = member.user;
91-
const { id: guildId } = member.guild;
85+
const { avatar: userAvatar } = member.user;
9286
const memberAvatar = member.avatar;
9387

9488
const avatarHash = memberAvatar || userAvatar;
9589
if (!avatarHash) return false;
9690

9791
const isAnimated = avatarHash.startsWith('a_');
98-
const ext = isAnimated ? '.gif' : '.png';
9992

10093
const url = memberAvatar
101-
? `${cdnBaseUrl}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}${ext}`
102-
: `${cdnBaseUrl}/avatars/${userId}/${avatarHash}${ext}`;
94+
? member.avatarURL()
95+
: member.user.avatarURL();
10396

10497
return {
10598
hash: avatarHash,

0 commit comments

Comments
 (0)