-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathleaderboard.js
42 lines (39 loc) · 1.22 KB
/
leaderboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const {
ChatInputCommandInteraction,
SlashCommandBuilder,
EmbedBuilder,
Client,
} = require("discord.js");
const DXP = require("discord-xp");
module.exports = {
data: new SlashCommandBuilder()
.setName("leaderboard")
.setDescription("Lists the top users when it comes to XP."),
/**
* @param {ChatInputCommandInteraction} interaction
* @param {Client} client
*/
async execute(interaction, client) {
const fetchLB = await DXP.fetchLeaderboard(interaction.guild.id, 10);
const leaderboard = await DXP.computeLeaderboard(client, fetchLB);
const embed = new EmbedBuilder().setColor("Blurple").setTimestamp();
const mappedLB = leaderboard.map(
(lb) =>
`**#${lb.position}** • **<@${lb.userID}>** • Level: \`${
lb.level
}\` • XP: \`${lb.xp - DXP.xpFor(lb.level)}/${
DXP.xpFor(lb.level + 1) - DXP.xpFor(lb.level)
}\``
);
return interaction.reply({
embeds: [
embed
.setTitle(`Leaderboard for ${interaction.guild.name}`)
.setDescription(
`${mappedLB.join("\n\n")}` ||
`This leaderboard is empty as there is currently no data to compute the leaderboard.`
),
],
});
},
};