Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update leaderboard.js [Fix of issue #458] #551

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/commands/information/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,25 @@ async function getRepLeaderboard(author) {
if (lb.length === 0) return "There are no users in the leaderboard";

let collector = "";
let rank = 1; // Track rank separately to avoid gaps

for (let i = 0; i < lb.length; i++) {
try {
// Try to fetch the user
const user = await author.client.users.fetch(lb[i].member_id);
collector += `**#${(i + 1).toString()}** - ${escapeInlineCode(user.tag)} [${lb[i].rep}]\n`;
collector += `**#${rank}** - ${escapeInlineCode(user.tag)} [${lb[i].rep}]\n`;
rank++; // Only increment if the user was found
} catch (ex) {
collector += `**#${(i + 1).toString()}** - DeletedUser#0000 [${lb[i].rep}]\n`;
// Skip if the user fetch fails (user might be deleted)
continue;
}
}

if (!collector) {
// No valid users were found in the leaderboard
return "No valid users found in the leaderboard.";
}

const embed = new EmbedBuilder()
.setAuthor({ name: "Reputation Leaderboard" })
.setColor(EMBED_COLORS.BOT_EMBED)
Expand Down