Haha-Yes/commands/purge

15 lines
780 B
Text
Raw Normal View History

2018-09-06 17:26:58 +02:00
exports.run = (client, message, args) => {
2018-09-06 18:42:40 +02:00
const user = message.mentions.users.first();
2018-09-06 17:26:58 +02:00
const amount = !!parseInt(message.content.split(' ')[1]) ? parseInt(message.content.split(' ')[1]) : parseInt(message.content.split(' ')[2])
if (!amount) return message.reply('Must specify an amount to delete!');
2018-09-06 18:42:40 +02:00
if (!amount && !user) return message.reply('Must specify a user and amount, or just an amount, of messages to purge!');
2018-09-06 17:26:58 +02:00
message.channel.fetchMessages({
limit: 100,
}).then((messages) => {
2018-09-06 18:42:40 +02:00
if (user) {
const filterBy = user ? user.id : Client.user.id;
messages = messages.filter(m => m.author.id === filterBy).array().slice(0, amount);
}
2018-09-06 17:26:58 +02:00
message.channel.bulkDelete(messages).catch(error => console.log(error.stack));
2018-09-06 18:42:40 +02:00
});
};