Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added content/docs/reference/all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/docs/reference/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
489 changes: 489 additions & 0 deletions content/docs/reference/components-v2.md

Large diffs are not rendered by default.

Binary file added content/docs/reference/container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/docs/reference/file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/docs/reference/gallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/docs/reference/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/docs/reference/section.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions content/docs/reference/templates/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,118 @@ object](/docs/reference/templates/syntax-and-data#message). Is also valid for ep

---

## Component V2

Components V2 provides a new way to create interactive and visually appealing message layouts in Discord applications,
making it easier to control message formatting and user interaction while maintaining line length under 120 characters.

### componentBuilder

`componentBuilder` simplifies building Discord's ComponentsV2, including buttons, menus, etc, in YAGPDB custom commands.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`componentBuilder` simplifies building Discord's ComponentsV2, including buttons, menus, etc, in YAGPDB custom commands.
A `componentBuilder` simplifies building Discord's ComponentsV2 in custom commands.


```yag
{{ $component := componentBuilder (sdict [text] [section] [gallery] [file] [separator] [container] [buttons] [menus] [interactive_components] [allowed_mentions] [reply] [silent] [ephemeral])}}
```

Returns a complex message object with the given components.

All keys are optional, but the Discord API will reject completey empty messages, so some content is required.

- `text`: A string or a slice of strings.
- `section`: A layout block that shows text with one optional accessory: a button **OR** a thumbnail with the following keys:
- `text`: A string or a slice of strings.
- `button`: A Button object, check [cbutton](#cbutton).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `button`: A Button object, check [cbutton](#cbutton).
- `button`: A [button object](#cbutton).

- `thumbnail`: A sdict with the following keys:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `thumbnail`: A sdict with the following keys:
- `thumbnail`: An sdict with the following keys:

- `media`: A string.
- `description`: A string.
- `spoiler`: A bool.
- `gallery`: Displays one or more media items with optional descriptions and spoiler flags with the following keys:
- `media`: A string.
- `description`: A string.
- `spoiler`: A bool.
- `file`: Attaches text files to the message and optionally displays them with the following keys:
- `content`: A string. (≤ 100,000 chars)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `content`: A string. ( 100,000 chars)
- `content`: A string. (max 100 000 chars)

- `name`: A string. (.txt appended automatically)
- `separator`: Adds spacing between components with the following keys:
- `true`: large separator
- `false` or `nil`: small separator
- `container`: Top-level layout. Containers offer the ability to visually encapsulate a collection of components,
and have an optional customizable accent color bar. Contains the following keys:
- `components`: [componentBuilder](#componentbuilder) or list of [componentBuilder](#componentbuilder).
- `color`: hex accent color (optional).
- `spoiler`: hides content until revealed (optional).
- `buttons`: Interactive buttons users can click. Can be single or multiple. see [cbutton](#cbutton).
- `menus`: Interactive menus users can select from. Can be single or multiple. see [cmenu](#cmenu).
- `interactive_components`: Mix of buttons and menus, auto-distributed. see [cbutton](#cbutton) and [cmenu](#cmenu).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `components`: [componentBuilder](#componentbuilder) or list of [componentBuilder](#componentbuilder).
- `color`: hex accent color (optional).
- `spoiler`: hides content until revealed (optional).
- `buttons`: Interactive buttons users can click. Can be single or multiple. see [cbutton](#cbutton).
- `menus`: Interactive menus users can select from. Can be single or multiple. see [cmenu](#cmenu).
- `interactive_components`: Mix of buttons and menus, auto-distributed. see [cbutton](#cbutton) and [cmenu](#cmenu).
- `components`: A [componentBuilder](#componentbuilder) or a slice thereof.
- `color`: hex accent color (optional).
- `spoiler`: hides content until revealed (optional).
- `buttons`: Interactive buttons users can click. Can be single or multiple.
- `menus`: Interactive [menu](#cmenu)s users can select from. Can be single or multiple.
- `interactive_components`: Mix of buttons and menus, auto-distributed.

This section is a little overlinked.

- `allowed_mentions`: A sdict with the following keys:
- `users`: A slice of user IDs.
- `roles`: A slice of role IDs.
- `everyone`: A bool.
- `replied_user`: A bool.
- `reply`: A sdict with the following keys:
- `message_id`: A string.
- `thread_id`: A string.
- `silent`: A bool.
- `ephemeral`: A bool.

### Component Builder Functions

The `ComponentBuilder` simplifies building Discord's V2 components, allowing complex layouts to be built incrementally.
It provides methods for constructing, manipulating, and exporting components in a format Discord understands,
ensuring line length doesn't exceed 120 characters.

#### ComponentBuilder.Add

Adds a single component entry to the builder under the given key.

```yag
{{ $builder := componentBuilder }}
{{ $builder.Add "key" "value" }}
```

- `key` – The top-level key for the component (e.g., "text", "section", "buttons").
- `value` – The component data (string, sdict, Button, SelectMenu, etc.).

#### ComponentBuilder.AddSlice

Adds multiple components under one key.

```yag
{{ $builder := componentBuilder }}
{{ $builder.AddSlice "key" (cslice "value1" "value2" "value3") }}
```

- `key` – The top-level key for the component (e.g., "text", "section", "buttons").
- `values` – The component data (string, sdict, Button, SelectMenu, etc.).

#### ComponentBuilder.Merge

Combine another builder into the current one.

```yag
{{ $builder1 := componentBuilder }}
{{ $builder2 := componentBuilder }}
{{ $builder1.Merge $builder2 }}
```

- `other` – The builder to merge.

#### ComponentBuilder.Get

Returns the component data for the given key.

```yag
{{ $builder := componentBuilder }}
{{ $builder.Add "key" "value" }}
{{ $value := $builder.Get "key" }}
```

- `key` – The top-level key for the component (e.g., "text", "section", "buttons").

Example usage can be found at the [Components v2](/docs/reference/components-v2).

---

## Math

#### abs
Expand Down
Binary file added content/docs/reference/texts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.