Recipes
Cooldown
Although you can implement your own cooldown logic, you might wanna try @slipher/cooldown first.
npm add @slipher/cooldownFirst 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:
| Property | Type | Description |
|---|---|---|
| type | CooldownType | target type, can be user, guild or channel |
| interval | number | time to refresh uses |
| uses | number | how 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 (.() + ), .)}`,
)
: ();
});