nyx/commands/Economy/lb.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-06-12 12:53:51 +02:00
const Levels = require("discord-xp");
const { Client, Message, MessageEmbed } = require("discord.js");
module.exports = {
name: "leaderboard",
aliases: ["lb"],
timeout: 5000,
usage: "Check the leaderboard of a server",
category: "Economy",
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async (client, message, args) => {
const rawLeaderboard = await Levels.fetchLeaderboard(message.guild.id, 10);
if (rawLeaderboard.length < 1)
return client.err(message, "Economy", "lb", 10);
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()
.setTitle(`**Leaderboard for ${message.guild.name}**`)
.setDescription(`\n${lb.join("\n")}`)
.setFooter(
`Requested by ${message.author.tag}`,
message.author.displayAvatarURL({ dynamic: true })
)
.setColor(client.color);
message.inlineReply(embed);
},
};