mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 16:55:55 +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 {
|
try {
|
||||||
const member = await guild.members.fetch(entry.userId);
|
const member = await guild.members.fetch(entry.userId);
|
||||||
const displayName = member ? member.displayName : entry.username; // Fallback if member not found
|
const displayName = member ? member.displayName : entry.username; // Fallback if member not found
|
||||||
return `${index + 1}. ${displayName}: ${
|
|
||||||
entry.correctAnswers
|
return {
|
||||||
} correct answers in ${entry.gamesPlayed} games`;
|
position: index + 1,
|
||||||
|
name: displayName,
|
||||||
|
correctAnswers: entry.correctAnswers,
|
||||||
|
gamesPlayed: entry.gamesPlayed,
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
`Error fetching member for userId: ${entry.userId}`,
|
`Error fetching member for userId: ${entry.userId}`,
|
||||||
error
|
error
|
||||||
);
|
);
|
||||||
return `${index + 1}. ${entry.username}: ${
|
return {
|
||||||
entry.correctAnswers
|
position: index + 1,
|
||||||
} correct answers in ${entry.gamesPlayed} games`;
|
name: entry.username,
|
||||||
|
correctAnswers: entry.correctAnswers,
|
||||||
|
gamesPlayed: entry.gamesPlayed,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -39,9 +46,19 @@ module.exports = {
|
||||||
const leaderboardEmbed = new EmbedBuilder()
|
const leaderboardEmbed = new EmbedBuilder()
|
||||||
.setColor("#0099ff")
|
.setColor("#0099ff")
|
||||||
.setTitle("Trivia Leaderboard")
|
.setTitle("Trivia Leaderboard")
|
||||||
.setDescription(leaderboardEntries.join("\n"))
|
|
||||||
.setTimestamp();
|
.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()) {
|
if (guild.iconURL()) {
|
||||||
leaderboardEmbed.setFooter({
|
leaderboardEmbed.setFooter({
|
||||||
text: guild.name,
|
text: guild.name,
|
||||||
|
|
Loading…
Reference in a new issue