@suaveplan/discord-client - Generic Discord API client for webhooks, bot messaging, and embeds with injectable fetch, OpenTelemetry instrumentation, and structured error codes
Generic Discord API client for webhooks, bot messaging, and embeds. Runtime-agnostic via injectable fetch and clock. Maps every documented Discord failure mode to a stable DISCORD.* error code and emits OpenTelemetry counters and histograms for every request.
Documentation tree
- bot-client — Implements the bot-token half of
@suaveplan/discord-client. Wraps the Discord Bot REST API (/channels/:id/messages,…
- discord-bot-client — Implements the bot-token half of
@suaveplan/discord-client. Wraps the Discord Bot REST API (/channels/:id/messages,…
- webhook — Implements the webhook half of
@suaveplan/discord-client. Discord webhooks are URLs that anyone with the URL can POST…
- discord-webhook — Implements the webhook half of
@suaveplan/discord-client. Discord webhooks are URLs that anyone with the URL can POST…
- errors — Defines the namespaced, frozen error-code registry and the typed
DiscordClientError class used by every runtime failu…
- discord-client-error — Defines the namespaced, frozen error-code registry and the typed
DiscordClientError class used by every runtime failu…
- http — Single funnel through which every Discord API and webhook request flows. It maps Discord response codes onto the `Disco…
- rate-limit — Parses Discord's three rate-limit response headers into a single millisecond back-off duration that callers can use to…
Installation
Quick Start
Modules
Subpath Exports
Error Codes
| Code |
HTTP |
Meaning |
DISCORD.API_ERROR |
502 |
Generic non-2xx bot response |
DISCORD.AUTH_ERROR |
401 |
Token rejected |
DISCORD.RATE_LIMITED |
429 |
Honour error.context.retryAfterMs |
DISCORD.CHANNEL_NOT_FOUND |
404 |
Channel missing or bot lacks access |
DISCORD.GUILD_NOT_FOUND |
404 |
Guild missing or bot is not a member |
DISCORD.CONFIG_MISSING |
500 |
Required config value missing |
DISCORD.INVALID_CONFIG |
500 |
Config failed Zod validation |
DISCORD.INVALID_MESSAGE |
400 |
Message payload failed Zod validation |
DISCORD.WEBHOOK_FAILED |
502 |
Webhook delivery rejected |
DISCORD.TIMEOUT |
504 |
Request aborted by timeout |
DISCORD.FORBIDDEN |
403 |
Caller lacks permissions |
Injectable Fetch & Clock
Both DiscordBotClient and DiscordWebhook accept fetch and clock injectables — pass deterministic stubs in tests, omit them in production to use globalThis.fetch and Date.now.
OTel Metrics
| Metric |
Type |
Labels |
discord_client.request.total |
Counter |
kind, method, outcome, status |
discord_client.request.duration_ms |
Histogram |
kind, method, outcome |