Skip to content

Commit

Permalink
Merge pull request #5 from ALPHACamp/features/API_leaderboard
Browse files Browse the repository at this point in the history
feat: replace discord username to guild nickname
  • Loading branch information
tim80411 authored Jul 16, 2023
2 parents 71eff3c + c3695ce commit 79b5ba9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// 使用 IntelliSense 以得知可用的屬性。
// 暫留以檢視現有屬性的描述。
// 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to pm2",
"type": "node",
"request": "attach",
"restart": true,
"port": 9229
}
]
}
8 changes: 5 additions & 3 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ router.get('/leaderboard', validate, async function (req, res) {

const fetchUserDetails = async (doc) => {
const data = doc.data();
const discordUser = await client.users.fetch(data.discordId);
const guild = await client.guilds.fetch(process.env.DISCORD_GUILDID);
const member = await guild.members.fetch(data.discordId);

return {
id: doc.id,
name: discordUser.username,
avatarURL: discordUser.displayAvatarURL(),
name: member.nickname || member.user.username,
avatarURL: member.user.displayAvatarURL(),
...data
};
};
Expand Down

0 comments on commit 79b5ba9

Please sign in to comment.