From c3695ce5cbf0da0819712140e8a1104f18fc6fe4 Mon Sep 17 00:00:00 2001 From: Timothy Liao Date: Sat, 15 Jul 2023 14:34:33 +0800 Subject: [PATCH] feat: replace discord username to guild nickname --- .vscode/launch.json | 15 +++++++++++++++ src/routes/index.js | 8 +++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c2248a4 --- /dev/null +++ b/.vscode/launch.json @@ -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 + } + ] +} \ No newline at end of file diff --git a/src/routes/index.js b/src/routes/index.js index 2422e66..72eaaae 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -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 }; };