woomy/src/commands/purge.js

61 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-03-09 01:11:33 +00:00
exports.run = async (client, message, args, level) => {
2020-01-25 10:02:43 +00:00
const settings = message.settings;
if(message.channel.name === settings.chatlogsChannel) {
return message.channel.send("<:error:466995152976871434> Can't purge logs.")
}
if(message.channel.name === settings.modlogsChannel) {
return message.channel.send("<:error:466995152976871434> Can't purge logs.")
}
const amount = !!parseInt(message.content.split(' ')[1]) ? parseInt(message.content.split(' ')[1]) : parseInt(message.content.split(' ')[2])
if(amount > 100) {
return message.channel.send("<:error:466995152976871434> Can only purge a maximum of 100 messages!")
}
2020-03-09 01:11:33 +00:00
if (!amount) return message.channel.send(
'<:error:466995152976871434> You didn\'t tell me how many messages to purge. Usage: \`' + client.commands.get(`purge`).help.usage + "`"
);
await message.delete().catch(O_o => {});
message.channel.messages.fetch({
limit: amount,
}).then((messages) => {
message.channel.bulkDelete(messages, true).catch(console.error);
message.channel.send(`<:success:466995111885144095> Purged ${amount} messages!`).then(m => m.delete({timeout: 5000}));
});
if (settings.modlogsChannel !== "off") {
const channel = message.guild.channels.cache.find(
channel => channel.name === settings.modlogsChannel
);
2020-01-25 10:02:43 +00:00
2020-03-09 01:11:33 +00:00
if (channel) {
let embed = new Discord.MessageEmbed();
embed.setColor("#a62019");
2020-03-16 01:21:19 +00:00
embed.setAuthor(`${amount} messages purged!`, message.author.avatarURL({format: "png", dynamic: true, size: 2048}));
2020-03-09 01:11:33 +00:00
embed.setDescription(`• Channel: ${message.channel.name} (${message.channel.id})\n• Mod: ${message.author} (${message.author.id})\n• Amount: \`${amount}\``)
try {
channel.send({ embed });
} catch (err) {
2020-01-25 10:02:43 +00:00
};
};
2020-03-09 01:11:33 +00:00
};
2020-01-25 10:02:43 +00:00
};
exports.conf = {
enabled: true,
guildOnly: true,
aliases: [],
permLevel: "Moderator",
requiredPerms: ["MANAGE_MESSAGES"]
};
exports.help = {
name: "purge",
category: "Moderation",
description: "Bulk deletes messages. **cannot delete messages older than 14 days.**",
usage: "purge [amount]"
};