nyx/commands/Utilities/rank.js

43 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-06-24 09:53:19 +02:00
const { MessageAttachment } = require("discord.js");
const Levels = require("discord-xp");
const canvacord = require("canvacord");
module.exports = {
name: "rank",
description: "Shows the current level and rank of the user!",
usage: "{User}",
timeout: 5000,
category: "Utilities",
2021-07-13 05:17:39 +02:00
Level: true,
2021-06-24 09:53:19 +02:00
run: async (client, message, args) => {
if (!message.guild) return;
if (message.author.bot) return;
const target =
message.mentions.users.first() ||
message.guild.members.cache.find(
r => r.user.username.toLowerCase() === args[0].toLocaleLowerCase()
) ||
message.guild.members.cache.find(
r => r.displayName.toLowerCase() === args[0].toLocaleLowerCase()
) ||
message.guild.members.cache.get(args[0]) ||
message.author;
const user = await Levels.fetch(target.id, message.guild.id, true);
if (!user) return client.err(message, "Utilities", "rank", 10);
const neededXp = Levels.xpFor(parseInt(user.level) + 1);
const Rank = new canvacord.Rank()
.setAvatar(target.displayAvatarURL({ dynamic: false, format: "png" }))
.setCurrentXP(user.xp)
.setRank(parseInt(user.position))
.setLevel(user.level)
.setRequiredXP(neededXp)
.setStatus(target.presence.status)
.setProgressBar("BLACK", "COLOR")
.setUsername(target.username)
.setDiscriminator(target.discriminator);
Rank.build().then(data => {
const attachment = new MessageAttachment(data, "RankCard.png");
message.inlineReply(attachment);
});
},
};