Webhooks
Create, list, send, and delete webhooks without sitting on the gateway.
A webhook is an ID plus a token that can post into a channel. Handy for scripts, CI, and anything that should not keep a gateway socket open.
Send without logging in as a bot
javascript
import { Client, Webhook } from '@fluxerjs/core';
const client = new Client({ intents: 0 });
const webhook = Webhook.fromToken(client, webhookId, webhookToken);
await webhook.send('Message from a script!');No login() required for token-based execute.
Create a webhook (bot auth)
Needs Manage Webhooks. The token is only returned on create. Store it. List/fetch will not give it back.
javascript
const client = new Client({ intents: 0 });
await client.login(process.env.FLUXER_BOT_TOKEN);
const channel = client.channels.get(channelId);
if (!channel?.createWebhook) throw new Error('Channel does not support webhooks');
const webhook = await channel.createWebhook({ name: 'My Webhook' });
console.log(webhook.id, webhook.token);Send content, embeds, overrides
Options are camelCase (avatarUrl, not avatar_url). Pass EmbedBuilder instances directly.
javascript
import { EmbedBuilder, Webhook } from '@fluxerjs/core';
const webhook = Webhook.fromToken(client, webhookId, webhookToken);
await webhook.send({
content: 'Hello from webhook!',
embeds: [
new EmbedBuilder().setTitle('Webhook Message').setColor(0x5865f2).setTimestamp(),
],
username: 'Custom Name',
avatarUrl: 'https://example.com/avatar.png',
});Plain text:
javascript
await webhook.send('Plain text message');List and delete
Listing needs a logged-in bot. Fetched webhooks usually have no token, so they cannot execute, but you can still edit or delete them with bot auth.
javascript
const channelHooks = await channel.fetchWebhooks();
const guildHooks = await guild.fetchWebhooks();
const webhook = await Webhook.fetch(client, webhookId);
await webhook.delete();Full bot example
webhook-bot wires !webhook create|list|send|delete. Attachments and embeds together: Webhook attachments and embeds.