Skip to content
GitHub

CooldownOptions

interface in meocord/interface Since 4.1.0

interface CooldownOptions<P = Record<string, unknown>>

What @Cooldown takes: the limit, whose calls count together, and how to exempt or tell calls apart.

P is the handler's second parameter, as by receives it.

Members

seconds

seconds: number

The window's length, in seconds: from 0.001 (a millisecond) to 4320000000000, counted in whole milliseconds, rounded. @Cooldown refuses anything else where it applies.

uses

uses?: number

Calls allowed within the window. A deploy that changes it keeps the calls counted so far, held to the new number; one that changes seconds starts the count again. A handler's cooldowns with the same seconds, per, by and bypass (the same function, or none) count the same calls, so they share one count, held to the smallest uses. The exception is two cooldowns over the same seconds and per, both with by or both without, whose by or bypass functions differ (two inline functions differ even when written alike): uses tells them apart, so changing it, or adding or removing another such cooldown, starts their counts again, and reordering two with the same uses swaps their counts.

Default: 1

per

per?: CooldownScope

Whose calls are counted together: 'user', 'guild', 'channel' or 'global'. Outside a server, 'guild' and 'channel' count per user.

Default: 'user'

bypass

bypass?: (context: ExecutionContext) => boolean | Promise<boolean>

Exempts a call, such as one from an owner, without counting it.

by

by?: (
  context: ExecutionContext,
  params: P,
) => CooldownKey | undefined | Promise<CooldownKey | undefined>

Counts calls apart by a value of the call, such as the account a button acts on, within the scope per names. It receives the handler's params as the handler does, after validation and pipes, and returns undefined to count the call as though there were no by. Declare the params it reads, and the handler's are checked against them; an error it throws goes to the exception filters.

See also

  • Cooldown