> For the complete documentation index, see [llms.txt](https://cjays-organization.gitbook.io/nexora.ts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cjays-organization.gitbook.io/nexora.ts/message-ui/button-builder.md).

# ButtonBuilder

Interactive buttons and action rows as plain API objects (`toJSON()`).

**Package:** `@nexora.ts/core`

## Beginner (shortest path)

```ts
import { btn, row, EmbedBuilder, type CommandContext } from '@nexora.ts/core';

export async function confirmDelete(ctx: CommandContext) {
  await ctx.reply({
    embed: EmbedBuilder.warn('Confirm', 'This cannot be undone.'),
    components: [
      row(
        btn.danger('delete:confirm', 'Delete'),
        btn.secondary('delete:cancel', 'Cancel'),
      ),
    ],
  });
}
```

Same with class statics: `ButtonBuilder.primary('id', 'Label')`, `row(...)`.

## Full fluent API

```ts
import {
  ButtonBuilder,
  ActionRowBuilder,
  EmbedBuilder,
  type CommandContext,
} from '@nexora.ts/core';

export async function confirmDelete(ctx: CommandContext) {
  const row = new ActionRowBuilder().add(
    new ButtonBuilder()
      .customId('delete:confirm', { prefix: true }) // → nexora:delete:confirm
      .label('Delete')
      .danger(),
    new ButtonBuilder().customId('delete:cancel').label('Cancel').secondary(),
    new ButtonBuilder().label('Docs').link('https://cjays-organization.gitbook.io/nexora.ts'),
  );

  await ctx.reply({
    embeds: [EmbedBuilder.warn('Confirm', 'This cannot be undone.').toJSON()],
    components: [row.toJSON()],
  });
}
```

## Button styles

| Helper                                      | Style                    |
| ------------------------------------------- | ------------------------ |
| `btn.primary(id, label)` / `.primary()`     | Blurple                  |
| `btn.secondary(id, label)` / `.secondary()` | Grey                     |
| `btn.success(id, label)` / `.success()`     | Green                    |
| `btn.danger(id, label)` / `.danger()`       | Red                      |
| `btn.link(url, label)` / `.link(url)`       | URL button (no customId) |

Also: `.label()`, `.emoji()`, `.disabled()`, `.customId(id, { prefix?: true })`.

## Selects (same rows)

```ts
import { ActionRowBuilder, StringSelectBuilder } from '@nexora.ts/core';

const row = new ActionRowBuilder().add(
  new StringSelectBuilder()
    .customId('role-pick', { prefix: true })
    .placeholder('Choose a role')
    .option('Admin', 'admin')
    .option({ label: 'Moderator', value: 'mod', emoji: '🛡️' }),
);
```

Also available: `UserSelectBuilder`, `RoleSelectBuilder`, `ChannelSelectBuilder`, `MentionableSelectBuilder`.

## Related

* [ModalBuilder](/nexora.ts/message-ui/modal-builder.md)
* [EmbedBuilder](/nexora.ts/message-ui/embed-builder.md)
* [Builders guide](/nexora.ts/builders-and-ui/builders.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cjays-organization.gitbook.io/nexora.ts/message-ui/button-builder.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
