JaBa/commands/Moderation/checkinvites.js

53 lines
1.4 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 Checkinvites extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "checkinvites",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["checkinvite", "checkinv"],
2021-12-10 21:39:54 +05:00
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 1000
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
const withInvite = [];
2021-12-30 20:03:36 +05:00
message.guild.members.cache.forEach((m) => {
2022-01-04 00:35:11 +05:00
const possibleLinks = m.presence.activities.map((a) => [a.state, a.details, a.name]).flat();
2021-12-10 21:39:54 +05:00
const inviteLinks = possibleLinks.filter((l) => /(discord\.(gg|io|me|li)\/.+|discordapp\.com\/invite\/.+)/i.test(l));
2021-12-11 01:11:50 +05:00
if (inviteLinks.length > 0) {
2021-12-10 21:39:54 +05:00
withInvite.push({
id: m.user.id,
tag: Discord.Util.escapeMarkdown(m.user.tag),
2021-12-24 20:52:27 +05:00
links: "**" + Discord.Util.escapeMarkdown(inviteLinks.join(", ")) + "**"
2021-12-10 21:39:54 +05:00
});
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
});
2021-12-24 20:52:27 +05:00
const text = (withInvite.length > 0 ? withInvite.map((m) => "`" + m.id + "` (" + m.tag + ") : " + m.links).join("\n") : message.translate("moderation/checkinvites:NOBODY"));
2021-12-10 21:39:54 +05:00
const embed = new Discord.MessageEmbed()
.setDescription(text)
.setColor(data.config.embed.color)
2022-01-04 00:35:11 +05:00
.setFooter({
text: data.config.embed.footer
});
2021-12-11 01:11:50 +05:00
2022-01-04 00:35:11 +05:00
const m = await message.channel.send({
embeds: [embed]
});
2021-12-26 19:29:37 +05:00
setTimeout(function () {
m.delete();
}, 3000);
2021-12-10 21:39:54 +05:00
}
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
module.exports = Checkinvites;