Recipes

Cooldown

Although you can implement your own cooldown logic, you might wanna try @slipher/cooldown first.

Installing...
npm add @slipher/cooldown

First you need to add cooldown property to client as shown below

import { , type UsingClient } from "seyfert";
import {  } from "@slipher/cooldown";
 
const  = new () as UsingClient & ;
 
.().(() => {
	. = new ();
})
 
declare module "seyfert" {
	interface UsingClient {
		: ;
	}
}

And then we can use @Cooldown() decorator in our commands, it takes 3 arguments:

PropertyTypeDescription
typeCooldownTypetarget type, can be user, guild or channel
intervalnumbertime to refresh uses
usesnumberhow many uses user can use this command in the given interval
import { , , type  } from "seyfert";
import { ,  } from "@slipher/cooldown";
 
@({
	: 'cool',
	: 'Reference command'
})
@({
	: .,
	: 1000 * 60,
	: {
		: 2
	},
})
export default class  extends  {
  async (: ) {
    await .({
      : `A cool command`
    });
  }
 
  (: , : string) {
    .({ :  })
  }
}

And then we need to create a middleware for handle when the user is in cooldown:

import { ,  } from 'seyfert';
import {  } from 'seyfert/lib/common';
 
export default <void>(async ({ , ,  }) => {
	const  = ...();
 
	typeof  === 'number'
		? (
				`You're in cooldown, try again ${.(new (.() + ), .)}`,
			)
		: ();
});