Skip to content

Commit

Permalink
made the /leaderboard command work
Browse files Browse the repository at this point in the history
  • Loading branch information
vb2007 committed Jul 28, 2024
1 parent d2fd8d9 commit 2e5908a
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions commands/economy/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,42 @@ module.exports = {
.addIntegerOption(option =>
option
.setName("amount")
.setDescription("The amount of top users to display.")
.setDescription("The amount of top users to display (MAX 100).")
.setRequired(false)
)
.setDMPermission(false),
async execute(interaction) {
var amount = interaction.options.getInteger("amount") || 10;

if(!interaction.inGuild()) {
var replyContent = "You can only check a member's balance in a server.";
}
else if (amount > 100){
var replyContent = "Cannot display more than 100 users.\nPlease try again with a smaller amount.";
}
else {

var embedReply = new EmbedBuilder({
color: 0x5F0FD6,
title: "Server leaderboard.",
description: replyContent,
timestamp: new Date().toISOString(),
footer: {
text: `Requested by: ${interaction.user.username}`,
icon_url: interaction.user.displayAvatarURL({ dynamic: true })
}
});

await interaction.reply({ embeds: [embedReply] });
var query = await db.query("SELECT userName, balance FROM economy ORDER BY balance DESC LIMIT ?", [amount]);

//logging
const response = JSON.stringify(embedReply.toJSON());
await logToFileAndDatabase(interaction, response);
var replyContent = query.map((user, index) =>
`${index + 1}. ${user.userName} : ${user.balance}$ :moneybag:`
).join("\n");
}

var embedReply = new EmbedBuilder({
color: 0x5F0FD6,
title: `Server leaderboard: TOP ${amount} users.`,
description: replyContent,
timestamp: new Date().toISOString(),
footer: {
text: `Requested by: ${interaction.user.username}`,
icon_url: interaction.user.displayAvatarURL({ dynamic: true })
}
});

await interaction.reply({ embeds: [embedReply] });

//logging
const response = JSON.stringify(embedReply.toJSON());
await logToFileAndDatabase(interaction, response);
}
}

0 comments on commit 2e5908a

Please sign in to comment.