Skip to content

Cooldown

Pure utility functions for cooldown and concurrency state management.

Cooldown . checkCooldown ( cooldowns commandName rules interaction )  -> number?

Returns the maximum remaining cooldown in seconds across all rules, or nil if no cooldown is active.

Parameters

cooldowns: {
{ [string]: number } }
commandName: string
rules: CooldownRule }
interaction: TypesCommand

Returns

number?
Cooldown . applyCooldown ( cooldowns commandName rules interaction )  -> ()

Records a cooldown expiry for each rule, keyed by the rule's per scope.

Parameters

cooldowns: {
{ [string]: number } }
commandName: string
rules: CooldownRule }
interaction: TypesCommand
Cooldown . acquireConcurrency ( concurrency commandName rule interaction )  -> boolean

Attempts to acquire a concurrency slot. Returns false if the limit for the scope is already reached.

Parameters

concurrency: {
{ [string]: number } }
commandName: string
rule: {
limit: number,
per: "user" | "guild" | "channel" | "member" | "global",
}
interaction: TypesCommand

Returns

boolean
Cooldown . releaseConcurrency ( concurrency commandName rule interaction )  -> ()

Releases a previously acquired concurrency slot.

Parameters

concurrency: {
{ [string]: number } }
commandName: string
rule: {
limit: number,
per: "user" | "guild" | "channel" | "member" | "global",
}
interaction: TypesCommand