Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

discord js clear message from id

//Updated to d.js v12 & fixed some bugs | 
// Input: [!clear @user <amount>] & [!clear <amount>] !Command name and prefix depend on your code!

		const user = message.mentions.users.first();

        let amount = !!parseInt(message.content.split(' ')[1]) ? parseInt(message.content.split(' ')[1]) : parseInt(message.content.split(' ')[2])
        amount = Math.floor(amount + 1);
        if (!amount) return message.reply('You need to specify an amount.');
        if (!amount && !user) return message.reply('You need to specify a user and an amount.');

        messages.channel.messages.fetch({
         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);
         } else {
            messages = amount;
         }
            message.channel.bulkDelete(messages).catch(error => console.log(error.stack));
        });
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript loop and array 
Javascript :: how to make apk of react native app 
Javascript :: boolean object js 
Javascript :: remove line break javascript 
Javascript :: Too long with no output (exceeded 10m0s): context deadline exceeded 
Javascript :: how to get single element from nested array mongoose 
Javascript :: how to scroll to an element javascript react 
Javascript :: show tooltip automatically 
Javascript :: how to cache data in javascript 
Javascript :: link react router dom 
Javascript :: change image onclick html 
Javascript :: iterate over array of objects javascript 
Javascript :: import modules js html 
Javascript :: reverse words in a string javascript 
Javascript :: compare two dates in javascript yyyy-mm-dd 
Javascript :: jquery attr 
Javascript :: react js marked import and use 
Javascript :: react-fragment 
Javascript :: get an array with unique values 
Javascript :: expo custom fonts 
Javascript :: replace all js 
Javascript :: How to make blinking/flashing text with jQuery 
Javascript :: download file from api vue 
Javascript :: include other js files in a js file 
Javascript :: deep merge nested objects javascript 
Javascript :: js text to html 
Javascript :: javascript declare a variable 
Javascript :: fetch function javascript 
Javascript :: javascript arithmetic operators 
Javascript :: jsx classname multiple 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =