cooldown.js
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

🚀 Getting started

Installation

Use the node package manager npm to install cooldown.js.

npm i cooldown.js

Example

const Discord = require('discord.js');
const Cooldown = require('cooldown.js');

const bot = new Discord.Client({
   intents: [
      Discord.Intents.FLAGS.GUILDS,
      Discord.Intents.FLAGS.GUILD_MESSAGES,
   ],
});

const cooldown = new Cooldown();

bot.on('ready', () => {
   console.log('Ready!');
});

bot.on('messageCreate', async (message) => {
   if (message.author.bot) return;

   if (message.content === '!ping') {
      const pingCooldown = new cooldown.Command(
         message.guild.id /* the guild id of the guild */,
         'ping' /* the command name */,
      ); // create a new cooldown for the command
      const userCooldown = pingCooldown.has(message.author.id); // get the cooldown for the user

      if (userCooldown) {
         // if the user has a cooldown
         message.reply(
            "You're on cooldown! Try again in " +
               userCooldown.secondsleft +
               ' seconds.',
         );
         return;
      }

      // if the user doesn't have a cooldown
      message.reply('Pong!');
      pingCooldown.add(
         message.author.id /* the user id */,
         1000 * 10 /* 10 seconds */,
      ); // add the user to the cooldown
   }
});

bot.login('your token');

Need help?

Discord Server

License

ISC

Package Sidebar

Install

npm i cooldown.js

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

6.67 kB

Total Files

6

Last publish

Collaborators

  • mxgnus