@lunibee/rest
v0.4.0
Published
> Discord REST client with bucket-aware rate limiting, retries, cancellation and typed routes.
Readme
@lunibee/rest
Discord REST client with bucket-aware rate limiting, retries, cancellation and typed routes.
bun add @lunibee/restimport { REST, Routes, RESTError } from "@lunibee/rest";
const rest = new REST({ token: process.env.DISCORD_TOKEN! });
const me = await rest.get<{ id: string; username: string }>(Routes.user());
try {
await rest.post(
Routes.channelMessages("123456789012345678"),
{ content: "Hello" },
{ reason: "greeting", signal: AbortSignal.timeout(5_000) },
);
} catch (error) {
if (error instanceof RESTError) console.error(error.status, error.message);
}Features
- Per-bucket queues keyed by Discord's bucket hash and major parameter, plus the global limit.
- Retries for 429s, 5xx and transport failures (
retries, or a customretryPolicy). AbortSignalsupport, including while queued.concurrentBuckets: true(opt-in) runs requests on a known bucket in parallel up to its remaining allowance. Off by default so per-bucket order is kept.- Shared rate limits across processes with
RedisRateLimitStore. hooksforonRequest,onResponse,onRateLimitandonRetry.WebhookClientfor sending through webhook URLs without a bot token.
Both call styles work: post(path, body, options) and post(path, { body, ...options }).
What's new in 0.2.0
RESTError.kind and retryable, token redaction in errors and hooks (redactPath()), and routes for polls, stickers, soundboard, SKUs, entitlements and subscriptions.
Docs: https://lunibee.js.org/core-concepts/rest/
