Skip to content
GitHub

CooldownError

class in meocord/common Since 4.1.0

class CooldownError extends Error

Thrown when a @Cooldown blocks a call, so the handler does not run.

Catch it in a filter to answer the caller your own way. Without one, the built-in fallback answers only the caller, with meocord.cooldown.until: the time the wait ends, which retryAt holds, as a Discord timestamp. A message command is not answered, unless messages.dmOnCooldown tells its author in a direct message, once per wait.

Examples

TypeScript
@Catch(CooldownError)
export class CooldownFilter implements ExceptionFilter<CooldownError> {
  async catch(error: CooldownError, context: ExecutionContext) {
    const interaction = context.getInteraction()
    if (interaction?.isRepliable()) {
      await interaction.reply({ content: `You can do that again ${time(error.retryAt, 'R')}.`, flags: MessageFlags.Ephemeral })
    }
  }
}

Members

constructor

new CooldownError(
  retryAfterMs: number,
  per: CooldownScope,
  limit?: CooldownLimit | undefined,
)

Parameters

NameTypeDescription
retryAfterMsnumber

How long until the next call is allowed.

perCooldownScope

The scope of the cooldown that blocked the call.

limit?CooldownLimit | undefined

The limit of the cooldown that blocked the call, as @Cooldown gives it: its uses and window.

limit

readonly limit?: CooldownLimit | undefined

per

readonly per: CooldownScope

retryAfterMs

readonly retryAfterMs: number

retryAt

readonly retryAt: Date

When the next call is allowed: when the error was made, plus CooldownError.retryAfterMs.