Skip to content

Bot SDK (@fluffwire/bot-sdk)

The official TypeScript/JavaScript SDK for building Fluffwire bots. It wraps the REST API and WebSocket gateway so you can focus on your bot's logic.

Installation

bash
npm install @fluffwire/bot-sdk

Requires Node.js 18 or newer.

Quick Start

typescript
import { FluffwireClient } from '@fluffwire/bot-sdk'

const client = new FluffwireClient({
  token: process.env.BOT_TOKEN!,
})

client.on('ready', () => {
  console.log('Bot is online!')
})

client.on('messageCreate', async (msg) => {
  if (msg.author.isBot) return
  if (msg.content === '!ping') {
    await client.sendMessage(msg.channelId, 'Pong! 🏓')
  }
})

await client.connect()

Constructor Options

typescript
new FluffwireClient(options: ClientOptions)
OptionTypeDefaultDescription
tokenstringrequiredYour bot token (with or without the Bot prefix)
baseUrlstringhttps://app.fluffwire.com/apiOverride the REST API base URL
wsUrlstringwss://app.fluffwire.com/wsOverride the WebSocket gateway URL

Events

Listen to gateway events with client.on(event, handler):

EventPayloadDescription
readyBot is connected and authenticated
messageCreateMessageA new message was sent in any visible channel
messageUpdateMessageA message was edited
messageDelete{ id, channelId }A message was deleted
reactionAdd{ messageId, channelId, userId, emoji }A reaction was added
reactionRemove{ messageId, channelId, userId, emoji }A reaction was removed
commandInvokeCommandInvokePayloadA slash command was invoked by a user
errorErrorA connection or protocol error occurred

Methods

connect()

typescript
await client.connect(): Promise<void>

Opens the WebSocket connection and resolves when ready is received. Automatically handles the IDENTIFY handshake and heartbeating.

disconnect()

typescript
client.disconnect(): void

Closes the WebSocket connection cleanly.

sendMessage(channelId, content)

typescript
await client.sendMessage(channelId: string, content: string | SendMessageOptions): Promise<Message>

Send a plain text message, or a structured message with attachments:

typescript
// Plain text
await client.sendMessage(channelId, 'Hello!')

// With attachment
await client.sendMessage(channelId, {
  content: 'Here is a file:',
  attachments: [{ url, filename: 'report.pdf' }],
})

toggleReaction(channelId, messageId, emoji)

typescript
await client.toggleReaction(channelId: string, messageId: string, emoji: string): Promise<void>

Adds a reaction if the bot hasn't reacted yet, or removes it if it has.

sendTyping(channelId)

typescript
await client.sendTyping(channelId: string): Promise<void>

Shows the bot as typing. Disappears after ~5 seconds or when a message is sent.

uploadFile(file, filename)

typescript
await client.uploadFile(file: Buffer | Blob, filename: string): Promise<{ url: string }>

Uploads a file and returns its hosted URL, which can then be passed as an attachment URL.

registerCommand(options)

typescript
await client.registerCommand(options: RegisterCommandOptions): Promise<BotCommand>

Registers a slash command for a server. Options:

FieldTypeDescription
namestringCommand name (lowercase, no spaces)
descriptionstringShown in the command picker
serverIdstringServer to register the command on
optionsCommandOption[]Optional list of command parameters

listCommands() / updateCommand() / deleteCommand()

typescript
await client.listCommands(): Promise<BotCommand[]>
await client.updateCommand(commandId: string, options: Partial<RegisterCommandOptions>): Promise<BotCommand>
await client.deleteCommand(commandId: string): Promise<void>

Manage existing registered commands.

Examples

The SDK repository includes runnable examples covering common patterns:

FileWhat it shows
01-connect.tsMinimal connect + ready event
02-send-message.tsSend text and attachment messages
03-receive-messages.tsEcho bot, message edit/delete events
04-slash-commands.tsRegister commands and handle invocations
05-reactions-and-typing.tsReact to messages, show typing indicator
06-file-upload.tsUpload a local file and attach to message
07-reaction-events.tsListen to reactionAdd/reactionRemove events
08-error-handling.tsAPI errors, partial failures, graceful shutdown
09-manage-commands.tsList, update, and delete registered commands

Run any example with:

bash
BOT_TOKEN=your_token CHANNEL_ID=your_channel_id npx tsx examples/02-send-message.ts

Reconnection

The SDK automatically reconnects when the WebSocket closes unexpectedly (non-1000 close codes). It will attempt to resume the session using the stored sessionId and sequence number. If resumption fails, it falls back to a fresh IDENTIFY.

Raw API Access (without SDK)

Prefer using the SDK, but if you need lower-level access see the REST API reference and WebSocket Gateway pages for the raw protocol documentation.

Licensed under CC BY-NC-SA 4.0.