Lunacord

Builders

The fluent, type-state builder APIs.

Every public API in @lunacord/core has a fluent builder. Most of them use TypeScript's type-state pattern — methods required for construction return a different builder type, so you can't call .build() (or .register(), or .connect()) until the required methods have been called.

LunacordBuilder

Used as Lunacord.create(). See Lunacord.

NodeBuilder

Used as lunacord.createNode(). See Node.

PlayerBuilder

Used as lunacord.createPlayer() (no args). See Player.

PluginBuilder

Used as lunacord.createPlugin("name", "1.0.0"). See Plugins.

FilterBuilder

Used as player.createFilterBuilder(). See Filters.

Builder pattern (example)

const plugin = lunacord
  .createPlugin({ name: "custom", version: "1.0.0", apiVersion: "2" })
  .observe((event, ctx) => ctx.logger.debug(`saw ${event.type}`))
  .beforeRestRequest(async (context) => ({ ...context, headers: { ...context.headers, "X-Bot": "me" } }))
  .build();

lunacord.use(plugin);

On this page