From b6cc76e28272d3fcf572d8032462ba20ff74105b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bersier?= Date: Thu, 6 Sep 2018 16:06:48 +0200 Subject: [PATCH] --- commands/purge.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 commands/purge.js diff --git a/commands/purge.js b/commands/purge.js new file mode 100644 index 0000000..a17831c --- /dev/null +++ b/commands/purge.js @@ -0,0 +1,15 @@ +exports.run = (client, message, args) => { + const user = message.mentions.users.first(); + 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!'); + if (!amount && !user) return message.reply('Must specify a user and amount, or just an amount, of messages to purge!'); + message.channel.fetchMessages({ + limit: 100, + }).then((messages) => { + if (user) { + const filterBy = user ? user.id : Client.user.id; + messages = messages.filter(m => m.author.id === filterBy).array().slice(0, amount); + } + message.channel.bulkDelete(messages).catch(error => console.log(error.stack)); + }); +}; \ No newline at end of file