Socket
Book a DemoInstallSign in
Socket

@discord-rose/cooldown-middleware

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@discord-rose/cooldown-middleware

Cooldown middleware for discord-rose

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

Cooldown Middleware

Cooldown middleware for discord-rose

Install

npm i @discord-rose/cooldown-middleware

Usage

Setting CommandOptions.cooldown to the amount of time (in milliseconds) to allow in between each command, will automatically add cooldowns.

When doing this, your CommandContext will have .invokeCooldown() enabled on it. You run this to invoke the cooldown.

const cooldownMiddleware = require('@discord-rose/cooldown-middleware')

worker.commands
  .middleware(cooldownMiddleware())
  .add({
    cooldown: 60e3, // 60 second cooldown time (in ms)
    command: '!hello',
    exec: (ctx) => {
      ctx.reply('World!')
      ctx.invokeCooldown() // this will invoke the 60 second cooldown
    }
  })

Custom message / time parsing

When using cooldownMiddleware() you can pass a function which takes a number that is the time that is remaining in a cooldown.

By default this is You're on cooldown, try again in ${(time / 1000).toFixed(0)}s, you can see how this might not scale well with over 2ish minutes of cooldown, as it only displays seconds.

Example for creating a custom message:

worker.commands
  .middleware(cooldownMiddleware((time) => { // amount of time left
    return `Try again in ${someTimeParser(time)}`
  }))

Keywords

discord-rose

FAQs

Package last updated on 13 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts