Skip to content
Functioncorev0.14.0

Cooldown

Allows limit uses per window, scoped by per. A number duration is seconds, and a string is a duration like 30m or 24h. A later refusal never burns the cooldown because the slot is charged in commit, only after the whole gate set passes. If two requests in one process pass the check together, the commit refuses the one that exceeds limit. The key combines the handler's route with the window settings, keeping two different handlers on separate windows. Replace the refusal with notice.

Throws:

  • A SeedcordTypeError when duration is a string that doesn't parse.

  • A SeedcordRangeError when duration is zero, negative, NaN, or Infinity.

See also:the @Gated decorator from your transport package, IRateLimiter

Cooldown<TDuration>(
    duration: number | ValidDuration<TDuration>,
    options?: CooldownOptions
): EffectGate<GateContextBase, "Cooldown">
// a number argument is SECONDS
\@Gated(Cooldown(5))
\@SlashRoute('daily')
class DailyHandler extends SlashHandler<'daily'> {
    async execute() {
        // ...
    }
}
// a string is a duration, here scoped per guild (the default is per user)
Cooldown('30m', { per: 'guild' });
// a burst, 3 uses per 10 minutes per user, then it refuses until a slot frees
\@Gated(Cooldown('10m', { limit: 3 }))
\@SlashRoute('report')
class ReportHandler extends SlashHandler<'report'> {
    async execute() {
        // ...
    }
}

TDuration

TDuration

duration

duration: number | ValidDuration<TDuration>

A number is seconds, and a string is a duration like 30m or 24h.

options?

options?: CooldownOptions

Sets the scope with per, the uses per window with limit, and the refusal with notice.