discordchan
v1.0.0
Published
Lightweight utility for posting messages or JSON payloads to a Discord channel via webhook, with optional dry-run mode for testing.
Downloads
50
Maintainers
Readme
discordchan
Canonical URL:
https://alexstevovich.com/a/discordchan-nodejs
Software URL:
https://midnightcitylights.com/software/discordchan-nodejs
A lightweight utility for sending messages or JSON payloads to Discord channels through webhook URLs.
Includes a dry-run mode for local testing without sending any real requests.
Installation
npm install discordchanExample
import DiscordChan from 'discordchan';
const chan = new DiscordChan('https://discord.com/api/webhooks/...');
// Send a simple message
await chan.send('Hello from DiscordChan!');
// Send a JSON object (auto-formatted as code block)
await chan.send({ status: 'OK', uptime: 4823 });
// Use dry-run mode to simulate messages without posting
chan.dryRunMode(true);
await chan.send('This will only log locally.');API
new DiscordChan(webhook, options?)
| Parameter | Type | Description |
|-----------------|----------|----------------------------------------------|
| webhook | string | Discord webhook URL. |
| options | object | Optional settings. |
| options.dryRun| boolean| If true, logs messages instead of sending. |
dryRunMode(enable = true)
Enables or disables dry-run simulation.
send(content)
Sends either a string or an object as a message.
If the content is an object, it is automatically formatted as a JSON code block.
verify()
Returns true if a valid webhook URL is set.
ensure()
Throws an error if the webhook URL is invalid.
Notes
- No external dependencies — works natively with Node 18+, Deno, or Bun.
- Automatically formats JSON payloads for Discord readability.
- Useful for build notifications, error reporting, or application logs.
- Fully compatible with asynchronous workflows.
License
Licensed under the Apache License 2.0.
