2021-06-12 12:53:51 +02:00
|
|
|
const Levels = require("discord-xp");
|
2021-09-17 18:28:39 +02:00
|
|
|
const { MessageEmbed } = require("discord.js");
|
2021-06-12 12:53:51 +02:00
|
|
|
module.exports = {
|
|
|
|
name: "leaderboard",
|
|
|
|
timeout: 5000,
|
2021-09-17 18:28:39 +02:00
|
|
|
description: "Check the leaderboard of a server",
|
2021-06-12 12:53:51 +02:00
|
|
|
category: "Economy",
|
2021-07-13 05:17:39 +02:00
|
|
|
Level: true,
|
2021-09-17 18:28:39 +02:00
|
|
|
run: async (client, interaction, args) => {
|
|
|
|
const rawLeaderboard = await Levels.fetchLeaderboard(
|
|
|
|
interaction.guild.id,
|
|
|
|
10
|
|
|
|
);
|
2021-06-12 12:53:51 +02:00
|
|
|
if (rawLeaderboard.length < 1)
|
2021-09-17 18:28:39 +02:00
|
|
|
return interaction.followUp({ content: "There isn't any data" });
|
2021-06-12 12:53:51 +02:00
|
|
|
const leaderboard = await Levels.computeLeaderboard(
|
|
|
|
client,
|
|
|
|
rawLeaderboard,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
const lb = leaderboard.map(
|
|
|
|
e =>
|
|
|
|
`**${e.position}**. ${e.username}#${e.discriminator} Level: ${
|
|
|
|
e.level
|
|
|
|
} XP: ${e.xp.toLocaleString()}`
|
|
|
|
);
|
|
|
|
const embed = new MessageEmbed()
|
2021-09-17 18:28:39 +02:00
|
|
|
.setTitle(`**Leaderboard for ${interaction.guild.name}**`)
|
2021-06-12 12:53:51 +02:00
|
|
|
.setDescription(`\n${lb.join("\n")}`)
|
|
|
|
.setFooter(
|
2021-09-17 18:28:39 +02:00
|
|
|
`Requested by ${interaction.user.tag}`,
|
|
|
|
interaction.user.displayAvatarURL({ dynamic: true })
|
2021-06-12 12:53:51 +02:00
|
|
|
)
|
|
|
|
.setColor(client.color);
|
2021-09-17 18:28:39 +02:00
|
|
|
interaction.followUp({ embeds: [embed] });
|
2021-06-12 12:53:51 +02:00
|
|
|
},
|
|
|
|
};
|