From 9b94d52c7674dd0ca3b38be40c72fae8b6a57490 Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Thu, 5 Sep 2024 20:15:38 +0100 Subject: [PATCH] Leaderboard: reformat how the users are displayed in the embed and make them more readable --- commands/fun/leaderboard.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/commands/fun/leaderboard.js b/commands/fun/leaderboard.js index 75eb28b..c09a329 100644 --- a/commands/fun/leaderboard.js +++ b/commands/fun/leaderboard.js @@ -21,17 +21,24 @@ module.exports = { try { const member = await guild.members.fetch(entry.userId); const displayName = member ? member.displayName : entry.username; // Fallback if member not found - return `${index + 1}. ${displayName}: ${ - entry.correctAnswers - } correct answers in ${entry.gamesPlayed} games`; + + return { + position: index + 1, + name: displayName, + correctAnswers: entry.correctAnswers, + gamesPlayed: entry.gamesPlayed, + }; } catch (error) { console.error( `Error fetching member for userId: ${entry.userId}`, error ); - return `${index + 1}. ${entry.username}: ${ - entry.correctAnswers - } correct answers in ${entry.gamesPlayed} games`; + return { + position: index + 1, + name: entry.username, + correctAnswers: entry.correctAnswers, + gamesPlayed: entry.gamesPlayed, + }; } }) ); @@ -39,9 +46,19 @@ module.exports = { const leaderboardEmbed = new EmbedBuilder() .setColor("#0099ff") .setTitle("Trivia Leaderboard") - .setDescription(leaderboardEntries.join("\n")) .setTimestamp(); + // Add each leaderboard entry + leaderboardEntries.forEach((entry) => { + const fieldValue = `${entry.correctAnswers} correct answers in ${entry.gamesPlayed} games`; + + leaderboardEmbed.addFields({ + name: `${entry.position}. ${entry.name}`, + value: fieldValue, + inline: false, + }); + }); + if (guild.iconURL()) { leaderboardEmbed.setFooter({ text: guild.name,