# Fluxerly.js Agent Cheatsheet

> Fluxerly.js is a Fluxer-native bot SDK for JavaScript, TypeScript and Effect. Requires Node.js 26.13 or newer, ESM and TypeScript 7

Voice: Fluxerly waits for Fluxer's new voice system and does not support voice over LiveKit. Fluxer is replacing LiveKit with its own voice system, which should arrive soon, and bot voice will come with it

These files describe SDK version 1003.1.1

## Requirements and install

- Package: `@neontechspace/fluxerly` (ESM-only, `"type": "module"` in `package.json`, Node.js 26.13 or newer)
- TypeScript: Node.js runs `.ts` directly without building. Typechecking requires TypeScript 7 and `@types/node`
- Entry points: `@neontechspace/fluxerly`, `/effect`, `/testing`, `/effect/testing`. Never import from `dist` or `src`

```sh
npm install @neontechspace/fluxerly
npx @neontechspace/fluxerly init --template ts
npx --no fluxerly agents
```

- Templates: `js`, `ts` or `effect`. Keep `FLUXER_BOT_TOKEN` in `.env` (never in code, logs or commits) and start with `node --env-file-if-exists=.env bot.js`

## Starter bot

Keep options in an exported `defineBot` object and start under `import.meta.main` so tests import `bot` without connecting

```ts
import { defineBot, runBot } from "@neontechspace/fluxerly"

export const bot = defineBot({
    commands: {
        prefix: "!",
        commands: { ping: { execute: ({ reply }) => reply("Pong!") } },
    },
})

if (import.meta.main) await runBot({ token: process.env.FLUXER_BOT_TOKEN, ...bot })
```

- `runBot` skips bot messages (`ignoreBots: false` disables), stops cleanly on SIGINT and SIGTERM (`processSignals: false` disables), logs fatal startup failures once and sets exit code 1
- Use `createClient({ token })` only for manual lifecycle control, registering handlers before `connect()` or `run()` and closing with `await using` or `shutdown()`

## Prefix commands, arguments, guards and cooldowns

```ts
import { commands, defineBot, guards } from "@neontechspace/fluxerly"

export const bot = defineBot({
    commands: {
        prefix: "!",
        parse: commands.parseQuoted,
        commands: {
            purge: {
                description: "Delete recent messages",
                guard: [guards.guildOnly(), guards.requirePermissions(["ManageMessages"])],
                cooldown: { durationMs: 30_000, per: "channel" },
                arguments: { count: { type: "integer", min: 1, max: 100, default: 10 } },
                execute: ({ values, reply }) => reply(`Deleting ${values.count} messages`),
            },
            help: { execute: ({ sendHelp }) => sendHelp() },
        },
    },
})
```

- Guards: `guards.guildOnly()`, `guards.dmOnly()`, `guards.ownerOnly()`, `guards.ownerOnly(ids)`, `guards.requirePermissions(names)`
- Cooldowns: `{ durationMs, per: "user" | "channel" | "guild" }`. `hidden: true` hides from help without blocking execution. Context also provides `sendHelp()`, `paginate(pages)`, `client` and `signal`

## Events, embeds, attachments and mentions

```ts
import { EmbedBuilder, defineBot, format } from "@neontechspace/fluxerly"

export const bot = defineBot({
    events: {
        messageCreate: async ({ message, reply }) => {
            if (message.content !== "!info") return
            const embed = new EmbedBuilder().title("Channel").description(format.channelMention(message.channelId))
            return reply({ embeds: [embed] })
        },
    },
})
```

- Outside handlers, call `client.messages.send(channelId, content)`. Wait for replies or reactions with `client.messages.collect` and `client.messages.collectReactions`
- Helpers: `EmbedBuilder`, `MessageBuilder`, `format`, `links`, `text`, `colors`. Keep IDs as decimal strings. Download attachments with `client.attachments.download({ maxBytes })` or `client.attachments.stream`
- Raw access: `client.rest.call("METHOD /path/{param}", { params, query, body })` (typed Fluxer names), `client.rest.request` (untyped) and `client.on("raw", handler)`

## Results, orThrow and onError

Network calls return `ResultAsync`. Await and check `isErr()` before reading `.value`, or unwrap with `orThrow`

```ts
import { createClient, describeError, errors, orThrow } from "@neontechspace/fluxerly"

await using client = createClient({ token: process.env.FLUXER_BOT_TOKEN })
const sent = await client.messages.send(channelId, "Hello")
if (sent.isErr()) {
    if (errors.apiCode(sent.error) === "missingPermissions") return
    console.error(describeError(sent.error))
}
const message = await orThrow(client.messages.send(channelId, "Hello again"))
```

- Return a `Result` from handlers so the SDK logs it or sends it to `onError`. Invalid local options throw `ConfigurationError` synchronously
- Before retrying, check `errors.isRetryable(err)`, wait `errors.retryAfterMs(err)`, and never retry an upload with `details.streamUsed`

## Zero-network testing

Test `defineBot` options with `createTestBot` from `@neontechspace/fluxerly/testing` (or `createTestClient`) against an in-memory Fluxer without a token or network

```ts
import assert from "node:assert/strict"
import { test } from "node:test"
import { createTestBot } from "@neontechspace/fluxerly/testing"
import { bot } from "./bot.js"

test("replies to !ping", async () => {
    await using testBot = createTestBot(bot)
    await testBot.ready()
    const sent = await testBot.say("!ping")
    assert.deepEqual(sent.map((message) => message.content), ["Pong!"])
})
```

- Controls: `ready()`, `say()`, `emit()`, `fixtures`, `rest.respond()`, `requests()`, `logs()`, `failures()`, `idle()` and `clock: "manual"` with `advance(ms)`
- Run tests with `node --test --test-timeout=10000 --test-force-exit`

## Effect entry point

Import `@neontechspace/fluxerly/effect` when using Effect 4 (within `peerDependencies.effect`). Compose with `Effect.gen` and `yield*`, keep clients in `Effect.scoped` or `FluxerClient.layer` / `FluxerClient.layerConfig`, pass `processSignals: true` to native `runBot` when not using `NodeRuntime.runMain`, and test with `@neontechspace/fluxerly/effect/testing`

## Patterns that do not exist in Fluxerly

- No `new Client()` or `client.login(token)`. Use `runBot` or `createClient` with `client.run()`
- No gateway intents. Presence updates for chosen members need `client.presence.setMembers`
- No slash commands or interactions yet. Commands are prefix commands under `commands`
- Messages are read-only data: No `message.reply()`, `message.delete()` or `channel.send()`. Use handler `reply` or `client.messages.send`
- A `runBot` event handler receives a context object such as `({ message, reply })`, not the message directly
- Bot authors check `message.author.isBot`, not `message.author.bot`
- Fluxer communities are named guilds in the SDK, as in `guildId`
- No voice channel connections over LiveKit yet (voice states, member voice controls, voice notes and audio or video attachments work)

## Deeper docs

- [Task index](https://fluxerly.neontechspace.com/docs/where-do-i.md)
- [JS/TS client methods by task](https://fluxerly.neontechspace.com/docs/api/tasks-js.md)
- [Effect client methods by task](https://fluxerly.neontechspace.com/docs/api/tasks-effect.md)
- [Condensed API reference](https://fluxerly.neontechspace.com/docs/llms-reference.txt)
- [Docs index](https://fluxerly.neontechspace.com/llms.txt) and [all guides](https://fluxerly.neontechspace.com/llms-full.txt)
