Leaderboard: remove avatar cause it looks weird

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

View file

@ -15,36 +15,23 @@ module.exports = {
.sort({ correctAnswers: -1 }) .sort({ correctAnswers: -1 })
.limit(10); .limit(10);
// Fetch display names and avatars for each leaderboard entry // Fetch display names for each leaderboard entry
const leaderboardEntries = await Promise.all( const leaderboardEntries = await Promise.all(
scores.map(async (entry, index) => { scores.map(async (entry, index) => {
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
const avatarUrl = member.user.displayAvatarURL({ return `${index + 1}. ${displayName}: ${
dynamic: true, entry.correctAnswers
size: 32, } correct answers in ${entry.gamesPlayed} games`;
}); // Get avatar URL
return {
position: index + 1,
name: displayName,
correctAnswers: entry.correctAnswers,
gamesPlayed: entry.gamesPlayed,
avatarUrl: avatarUrl,
};
} 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 { return `${index + 1}. ${entry.username}: ${
position: index + 1, entry.correctAnswers
name: entry.username, } correct answers in ${entry.gamesPlayed} games`;
correctAnswers: entry.correctAnswers,
gamesPlayed: entry.gamesPlayed,
avatarUrl: null, // No avatar in case of error
};
} }
}) })
); );
@ -52,22 +39,9 @@ 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 with avatar as a thumbnail
leaderboardEntries.forEach((entry) => {
const fieldValue = `${entry.correctAnswers} correct answers in ${entry.gamesPlayed} games`;
leaderboardEmbed.addFields({
name: `${entry.position}. ${entry.name}`,
value: fieldValue,
inline: false,
});
// Use the avatar URL as a thumbnail for each user entry
leaderboardEmbed.setThumbnail(entry.avatarUrl || null);
});
if (guild.iconURL()) { if (guild.iconURL()) {
leaderboardEmbed.setFooter({ leaderboardEmbed.setFooter({
text: guild.name, text: guild.name,