mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 00:35:56 +00:00
Leaderboard: reformat how the users are displayed in the embed and make them more readable
This commit is contained in:
parent
859fa3124b
commit
9b94d52c76
1 changed files with 24 additions and 7 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue