Leaderboard: reformat how the users are displayed in the embed and make them more readable

This commit is contained in:
Ayden Jahola 2024-09-05 20:15:38 +01:00
parent 859fa3124b
commit 9b94d52c76
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742

View file

@ -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,