Skip to content

Commit 0b73437

Browse files
authored
fix: ensure Images are produced for discord (#734)
1 parent 0327b90 commit 0b73437

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/providers/discord.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ export default (options) => {
77
scope: 'identify email',
88
params: { grant_type: 'authorization_code' },
99
accessTokenUrl: 'https://discord.com/api/oauth2/token',
10-
authorizationUrl:
11-
'https://discord.com/api/oauth2/authorize?response_type=code&prompt=none',
10+
authorizationUrl: 'https://discord.com/api/oauth2/authorize?response_type=code&prompt=none',
1211
profileUrl: 'https://discord.com/api/users/@me',
1312
profile: (profile) => {
13+
if (profile.avatar === null) {
14+
const defaultAvatarNumber = parseInt(profile.discriminator) % 5
15+
profile.image_url = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNumber}.png`
16+
} else {
17+
const format = profile.premium_type === 1 || profile.premium_type === 2 ? 'gif' : 'png'
18+
profile.image_url = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`
19+
}
1420
return {
1521
id: profile.id,
1622
name: profile.username,
17-
image: `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.png`,
23+
image: profile.image_url,
1824
email: profile.email
1925
}
2026
},

0 commit comments

Comments
 (0)