Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

discord.js cooldown

// Add this at the top of your JS file:
// First, this must be at the top level of your code, **NOT** in any event!
const talkedRecently = new Set();


//Now in the command event add this:
    if (talkedRecently.has(userid)) {
       console.log("Wait 1 minute before getting typing this again. - " + userid);
    } else {
      
      console.log('Hello! How are you?')
      
        talkedRecently.add(userid);
        setTimeout(() => {
          // Removes the user from the set after a minute
          talkedRecently.delete(userid);
        }, 60000);
    }
Comment

discord.js command cooldown

bot.on('message', (message) => {
    if (!message.content.startsWith(PREFIX) || message.author.bot) return;

    const args = message.content
        .toLowerCase()
        .slice(PREFIX.length)
        .trim()
        .split(/s+/);
    const [command, input] = args;

    if (command === 'clear' || command === 'c') {
        if (!message.member.hasPermission('MANAGE_MESSAGES')) {
            return message.channel
                .send(
                    "Sorry, ale nemáš na to dostatečná práva (`MANAGE_MESSAGES`) :shield: ",
                );
        }

        if (isNaN(input)) {
            return message.channel
                .send('Napiš kolik zpráv mám smazat :eyes: ')
                .then((sent) => {
                    setTimeout(() => {
                        sent.delete();
                    }, 2500);
                });
        }

        if (Number(input) < 0) {
            return message.channel
                .send('Brácho .... rozumím, nemažu nic :clown: ')
                .then((sent) => {
                    setTimeout(() => {
                        sent.delete();
                    }, 2500);
                });
        }

        // add an extra to delete the current message too
        const amount = Number(input) > 100 ?
            101 :
            Number(input) + 1;

        message.channel.bulkDelete(amount, true)
            .then((_message) => {
                message.channel
                    // do you want to include the current message here?
                    // if not it should be ${_message.size - 1}
                    .send(`Smazal jsem `${_message.size}` zpráv :broom:`)
                    .then((sent) => {
                        setTimeout(() => {
                            sent.delete();
                        }, 2500);
                    });
            });
    }

    if (command === 'help' && input === 'clear') {
        const embed = new Discord.MessageEmbed()
            .setColor('#00B2B2')
            .setTitle('**Clear Help**')
            .setDescription(
                `Tento příkaz maže správy. Například takto: `${PREFIX}clear 5` nebo `${PREFIX}c 5`.`,
            )
            .setFooter(
                `Vyžádáno uživatelem: ${message.author.tag}`,
                message.author.displayAvatarURL(),
            )
            .setTimestamp();

        message.channel.send(embed);
    }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: check if string contains a value in array 
Javascript :: double bang js 
Javascript :: puppeter loop 
Javascript :: javascript casting objects 
Javascript :: react-validex 
Javascript :: callbacks in jquery 
Javascript :: jquery set timezone 
Javascript :: flatmap js 
Javascript :: regex javascript matching first letter to last 
Javascript :: como ordenar um array em ordem crescente javascript 
Javascript :: mongodb aggregate $filter check if exists 
Javascript :: how to read if a person has send a message on discord.js 
Javascript :: javascript sucks 
Javascript :: js get external script to currnet page 
Javascript :: Supported by YAML but not supported by JSON: 
Javascript :: unity overlap box 
Javascript :: Check if a number is even or odd 
Javascript :: TypeError: Expected a string but received a undefined 
Javascript :: mock anonymous function jest 
Javascript :: react copy array 
Python :: minecraft 
Python :: opencv show image jupyter 
Python :: python - show all columns / rows of a Pandas Dataframe 
Python :: convert column in pandas to datetime 
Python :: how to return PIL image from opencv 
Python :: pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple 
Python :: install serial python 
Python :: add bearer token in python request 
Python :: python urlencode 
Python :: flip a plot matplotlib 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =