Skip to content

Package

rate-limiter v0.1.12

Changelog

seedcordseedcord

The whole Discord bot, typed end to end

Website · Guide · Reference · Discord

npm node bun license

About

@seedcord/rate-limiter gives you MemoryRateLimiter and buildKey. Each transport constructs one in its Seedcord constructor and assigns it to core.rateLimiter. The Cooldown gate reads it from there. A handler gets the same instance from this.core.rateLimiter.

MemoryRateLimiter counts in one process, so it resets on restart and stays per-isolate on serverless. Pass your own Store<'charge'> as config.store to keep the counts across restarts and isolates.

Until v1.0.0, minor versions can break.

Installation

Your transport already re-exports this.

pnpm add @seedcord/rate-limiter

Usage

buildKey joins a prefix and its parts with :, substituting global for a null part, so two features never collide on one user id:

import { buildKey, MemoryRateLimiter } from '@seedcord/rate-limiter';

const limiter = new MemoryRateLimiter();
const key = buildKey('daily', interaction.user.id);

The Cooldown gate covers the common case. Call this.core.rateLimiter from a handler when the gate has no option for the window you want.