Skip to content

Commit 56b1235

Browse files
committed
component v2 Docs
1 parent 73b923c commit 56b1235

File tree

10 files changed

+550
-0
lines changed

10 files changed

+550
-0
lines changed

content/docs/reference/all.png

147 KB
Loading

content/docs/reference/button.png

22.7 KB
Loading

content/docs/reference/components-v2.md

Lines changed: 452 additions & 0 deletions
Large diffs are not rendered by default.
15.1 KB
Loading

content/docs/reference/file.png

19.6 KB
Loading

content/docs/reference/gallery.png

352 KB
Loading

content/docs/reference/menu.png

24.2 KB
Loading

content/docs/reference/section.png

14.9 KB
Loading

content/docs/reference/templates/functions.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,104 @@ object](/docs/reference/templates/syntax-and-data#message). Is also valid for ep
779779

780780
---
781781

782+
## Component V2
783+
784+
Components V2 introduces a new way to create interactive and visually appealing message layouts in Discord applications, allowing for greater control over message formatting and user interaction.
785+
786+
### componentBuilder
787+
788+
`componentBuilder` is a helper for building Discord's new Components V2 (sections, buttons, menus, galleries, etc.) in YAGPDB custom commands.
789+
790+
```yag
791+
{{ $component := componentBuilder (sdict [text] [section] [gallery] [file] [separator] [container] [buttons] [menus] [interactive_components] [allowed_mentions] [reply] [silent] [ephemeral])}}
792+
```
793+
Returns a complex message object with the given components.
794+
795+
All keys are optional, but the Discord API will reject completey empty messages, so some content is required.
796+
797+
- `text`: A string or a slice of strings.
798+
- `section`: A layout block that shows text with one optional accessory: a button **OR** a thumbnail with the following keys:
799+
- `text`: A string or a slice of strings.
800+
- `button`: A Button object, check [cbutton](#cbutton).
801+
- `thumbnail`: A sdict with the following keys:
802+
- `media`: A string.
803+
- `description`: A string.
804+
- `spoiler`: A bool.
805+
- `gallery`: Displays one or more media items with optional descriptions and spoiler flags with the following keys:
806+
- `media`: A string.
807+
- `description`: A string.
808+
- `spoiler`: A bool.
809+
- `file`: Attaches text files to the message and optionally displays them with the following keys:
810+
- `content`: A string. (≤ 100,000 chars)
811+
- `name`: A string. (.txt appended automatically)
812+
- `separator`: Adds spacing between components with the following keys:
813+
- `true`: large separator
814+
- `false` or `nil`: small separator
815+
- `container`: top-level layout component. containers offer the ability to visually encapsulate a collection of components and have an optional customizable accent color bar. with the following keys:
816+
- `components`: [componentbuilder](#componentbuilder) or list of [componentbuilder](#componentbuilder).
817+
- `color`: hex accent color (optional).
818+
- `spoiler`: hides content until revealed (optional).
819+
- `buttons`: Interactive buttons users can click. Can be single or multiple. see [cbutton](#cbutton).
820+
- `menus`: Interactive menus users can select from. Can be single or multiple. see [cmenu](#cmenu).
821+
- `interactive_components`: Mix of buttons and menus, auto-distributed. see [cbutton](#cbutton) and [cmenu](#cmenu).
822+
- `allowed_mentions`: A sdict with the following keys:
823+
- `users`: A slice of user IDs.
824+
- `roles`: A slice of role IDs.
825+
- `everyone`: A bool.
826+
- `replied_user`: A bool.
827+
- `reply`: A sdict with the following keys:
828+
- `message_id`: A string.
829+
- `thread_id`: A string.
830+
- `silent`: A bool.
831+
- `ephemeral`: A bool.
832+
833+
### Component Builder Functions
834+
835+
The `ComponentBuilder` object provides methods to construct, manipulate, and export Discord V2 message components programmatically. These methods allow you to build complex layouts incrementally and retrieve them in a format that Discord understands.
836+
837+
#### ComponentBuilder.Add
838+
839+
Adds a single component entry to the builder under the given key.
840+
```yag
841+
{{ $builder := componentBuilder }}
842+
{{ $builder.Add "key" "value" }}
843+
```
844+
845+
- `key` – The top-level key for the component (e.g., "text", "section", "buttons").
846+
- `value` – The component data (string, sdict, Button, SelectMenu, etc.).
847+
848+
#### ComponentBuilder.AddSlice
849+
Adds multiple components under one key.
850+
```yag
851+
{{ $builder := componentBuilder }}
852+
{{ $builder.AddSlice "key" (cslice "value1" "value2" "value3") }}
853+
```
854+
855+
- `key` – The top-level key for the component (e.g., "text", "section", "buttons").
856+
- `values` – The component data (string, sdict, Button, SelectMenu, etc.).
857+
858+
#### ComponentBuilder.Merge
859+
Combine another builder into the current one.
860+
```yag
861+
{{ $builder1 := componentBuilder }}
862+
{{ $builder2 := componentBuilder }}
863+
{{ $builder1.Merge $builder2 }}
864+
```
865+
- `other` – The builder to merge.
866+
867+
#### ComponentBuilder.Get
868+
Returns the component data for the given key.
869+
```yag
870+
{{ $builder := componentBuilder }}
871+
{{ $builder.Add "key" "value" }}
872+
{{ $value := $builder.Get "key" }}
873+
```
874+
- `key` – The top-level key for the component (e.g., "text", "section", "buttons").
875+
876+
Example usage can be found at the [Components v2](../components-v2.md).
877+
878+
---
879+
782880
## Math
783881

784882
#### abs

content/docs/reference/texts.png

18.5 KB
Loading

0 commit comments

Comments
 (0)