JaBa/commands/General/invitations.js

66 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js");
class Invitations extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "invitations",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: [],
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS", "MANAGE_GUILD"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 2000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
let member = await this.client.resolveMember(args[0], message.guild);
if (!member) member = message.member;
const invites = await message.guild.fetchInvites().catch(() => {});
if (!invites) return message.error("misc:ERR_OCCURRED");
const memberInvites = invites.filter((i) => i.inviter && i.inviter.id === member.user.id);
if (memberInvites.size <= 0) {
if (member === message.member) {
return message.error("general/invitations:NOBODY_AUTHOR");
} else {
2021-12-26 19:29:37 +05:00
return message.error("general/invitations:NOBODY_MEMBER", {
member: member.user.tag
});
2021-12-10 21:39:54 +05:00
};
};
const content = memberInvites.map((i) => {
2021-12-26 19:29:37 +05:00
return message.translate("general/invitations:CODE", {
uses: i.uses,
code: i.code,
channel: i.channel.toString()
});
2021-12-10 21:39:54 +05:00
}).join("\n");
let index = 0;
memberInvites.forEach((invite) => index += invite.uses);
const embed = new Discord.MessageEmbed()
.setColor(data.config.embed.color)
.setFooter(data.config.embed.footer)
.setAuthor(message.translate("general/invitations:TRACKER"))
.setDescription(message.translate("general/invitations:TITLE", {
member: member.user.tag,
guild: message.guild.name
}))
.addField(message.translate("general/invitations:FIELD_INVITED"), message.translate("general/invitations:FIELD_MEMBERS", {
total: index
}))
.addField(message.translate("general/invitations:FIELD_CODES"), content);
message.channel.send(embed);
}
};
module.exports = Invitations;