discord js clear message from id

Solutions on MaxInterview for discord js clear message from id by the best coders in the world

showing results for - "discord js clear message from id"
Evann
25 Jan 2021
1//Updated to d.js v12 & fixed some bugs | 
2// Input: [!clear @user <amount>] & [!clear <amount>] !Command name and prefix depend on your code!
3
4		const user = message.mentions.users.first();
5
6        let amount = !!parseInt(message.content.split(' ')[1]) ? parseInt(message.content.split(' ')[1]) : parseInt(message.content.split(' ')[2])
7        amount = Math.floor(amount + 1);
8        if (!amount) return message.reply('You need to specify an amount.');
9        if (!amount && !user) return message.reply('You need to specify a user and an amount.');
10
11        messages.channel.messages.fetch({
12         limit: 100,
13        }).then((messages) => {
14         if (user) {
15         const filterBy = user ? user.id : Client.user.id;
16         messages = messages.filter(m => m.author.id === filterBy).array().slice(0, amount);
17         } else {
18            messages = amount;
19         }
20            message.channel.bulkDelete(messages).catch(error => console.log(error.stack));
21        });