Skip to content

Commit 35c2211

Browse files
committed
added blank lines around headers and code blocks (lint fix) and used absolute link to link the file
1 parent c5637e5 commit 35c2211

File tree

2 files changed

+60
-17
lines changed

2 files changed

+60
-17
lines changed

content/docs/reference/components-v2.md

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ description = "Be fancier, use components!"
55
+++
66

77
## componentBuilder
8+
89
`componentBuilder` is a helper for building Discord’s new Components V2 (sections, buttons, menus, galleries, etc.) in YAGPDB custom commands.
910

1011
It provides a simple template-based way to assemble complex message layouts without needing to write raw JSON. Instead, you describe components with key–value pairs (sdict, strings, arrays), and `componentBuilder` handles conversion and validation for you.
@@ -23,7 +24,8 @@ Displays plain text content, supporting markdown. Can be a string or a slice of
2324
`text`: string | []string
2425

2526
Example:
26-
```go
27+
28+
```yag
2729
{{$text := componentBuilder (sdict
2830
"text" "Component Builder v2 test!"
2931
)}}
@@ -38,6 +40,7 @@ Example:
3840
)}}
3941
{{sendMessage nil $text}}
4042
```
43+
4144
![example of text](texts.png)
4245

4346
### Section
@@ -49,7 +52,8 @@ A layout block that shows text with one optional accessory: a button OR a thumbn
4952
`button`: Button (optional)
5053

5154
`thumbnail`: sdict with keys media, description, spoiler (optional)
52-
```go
55+
56+
```yag
5357
{{$section := componentBuilder (sdict
5458
"section" (sdict
5559
"text" "🍲 **Lasagna Recipe**"
@@ -62,9 +66,13 @@ A layout block that shows text with one optional accessory: a button OR a thumbn
6266
)
6367
)}}
6468
```
69+
6570
{{< callout context="note" icon="outline/info-circle" >}}
71+
6672
The above example shows `button` and `thumbnail` in `section`, however you can use only one of them, not both at same time.
73+
6774
{{< /callout >}}
75+
6876
![example of section](section.png)
6977

7078
### Gallery
@@ -76,7 +84,8 @@ Displays one or more media items with optional descriptions and spoiler flags.
7684
`description`: string (optional)
7785

7886
`spoiler`: bool (optional)
79-
```go
87+
88+
```yag
8089
{{$gallery := componentBuilder (sdict
8190
"gallery" (cslice
8291
(sdict "media" "https://http.cat/103")
@@ -85,6 +94,7 @@ Displays one or more media items with optional descriptions and spoiler flags.
8594
)
8695
)}}
8796
```
97+
8898
![example of gallery](gallery.png)
8999

90100
### File
@@ -94,7 +104,8 @@ Attaches text files to the message and optionally displays them.
94104
`content`: string (≤ 100,000 chars)
95105

96106
`name`: string (filename, .txt appended automatically)
97-
```go
107+
108+
```yag
98109
{{$file := componentBuilder (sdict
99110
"file" (cslice
100111
(sdict
@@ -109,6 +120,7 @@ Attaches text files to the message and optionally displays them.
109120
)
110121
)}}
111122
```
123+
112124
![example of file](file.png)
113125

114126
### Separator
@@ -118,7 +130,8 @@ Adds spacing between components.
118130
`true`: large separator
119131

120132
`false` or `nil`: small separator
121-
```go
133+
134+
```yag
122135
{{$separator := componentBuilder (sdict "separator" true)}}
123136
```
124137

@@ -132,7 +145,7 @@ Groups multiple components with optional styling.
132145

133146
`spoiler`: hides content until revealed (optional)
134147

135-
```go
148+
```yag
136149
{{$container := sdict
137150
"color" 0xF5CDF6
138151
"spoiler" false
@@ -148,6 +161,7 @@ Groups multiple components with optional styling.
148161
"container" $container
149162
)}}
150163
```
164+
151165
![example of container](container.png)
152166

153167
### Buttons
@@ -157,7 +171,8 @@ Interactive buttons users can click. Can be single or multiple. see [cbutton](..
157171
- Maximum 25 buttons total (5 rows × 5 buttons)
158172

159173
- Link buttons don’t need a `custom_id`
160-
```go
174+
175+
```yag
161176
{{$buttons := componentBuilder (sdict
162177
"buttons" (cslice
163178
(cbutton (sdict "label" "-" "custom_id" "decrease" "style" "danger"))
@@ -166,6 +181,7 @@ Interactive buttons users can click. Can be single or multiple. see [cbutton](..
166181
)
167182
)}}
168183
```
184+
169185
![example of buttons](button.png)
170186

171187
### Menus
@@ -175,7 +191,8 @@ Select menus for user options. see [cmenu](../reference/templates/functions.md#c
175191
- Maximum 5 menus per message
176192

177193
- Each menu occupies its own row
178-
```go
194+
195+
```yag
179196
{{$menu := componentBuilder (sdict
180197
"menus" (cmenu (sdict
181198
"custom_id" "unit-select"
@@ -187,6 +204,7 @@ Select menus for user options. see [cmenu](../reference/templates/functions.md#c
187204
)))
188205
}}
189206
```
207+
190208
![example of menus](menu.png)
191209

192210
### Interactive Components
@@ -200,7 +218,8 @@ Accepts:
200218
- Slice of components
201219

202220
- Slice of slices (to define rows)
203-
```go
221+
222+
```yag
204223
{{$interactive := componentBuilder (sdict "interactive_components" (cslice
205224
(cbutton (sdict "label" "Approve" "custom_id" "approve" "style" "success"))
206225
(cbutton (sdict "label" "Reject" "custom_id" "reject" "style" "danger"))
@@ -226,8 +245,10 @@ Accepts:
226245
- `ephemeral`: message visible only to interaction user
227246

228247
### Example
248+
229249
This example combines text, sections, gallery, files, buttons, menus, and container styling into a single, cohesive layout.
230-
```go
250+
251+
```yag
231252
{{$section := sdict
232253
"text" "🍲 **Lasagna Recipe**"
233254
"button" (cbutton (sdict "label" "Set Servings" "custom_id" "set-servings" "style" "primary"))
@@ -293,20 +314,24 @@ This example combines text, sections, gallery, files, buttons, menus, and contai
293314
)}}
294315
{{sendMessage nil $comp}}
295316
```
317+
296318
![example of full](all.png)
297319

298320
## Component Builder Helper Functions
299321

300322
The `componentBuilder` helper function provides methods to construct, manipulate, and get Discord V2 message components programmatically. These methods allow you to build complex layouts incrementally and retrieve them in a format that Discord understands.
301323

302324
### componentBuilder.Add
325+
303326
Adds a single component entry to the builder under the given key.
327+
304328
- Parameters:
305329
- `key` – The top-level key for the component (e.g., "text", "section", "buttons").
306330
- `value` – The component data (string, sdict, Button, SelectMenu, etc.).
307331

308332
- Example:
309-
```go
333+
334+
```yag
310335
{{$builder := componentBuilder}}
311336
{{$section := sdict
312337
"text" "🍲 **Lasagna Recipe**"
@@ -316,14 +341,16 @@ Adds a single component entry to the builder under the given key.
316341
```
317342

318343
### componentBuilder.AddSlice
319-
Adds multiple components under one key.
344+
A
345+
dds multiple components under one key.
320346

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

325351
- Example:
326-
```go
352+
353+
```yag
327354
{{$builder := componentBuilder}}
328355
{{$pasta := cslice
329356
"### Ingredients"
@@ -337,13 +364,15 @@ Adds multiple components under one key.
337364
```
338365

339366
### componentBuilder.Merge
367+
340368
Combine another builder into the current one.
341369

342370
- Parameters:
343371
- `other` – The builder to merge.
344372

345373
- Example:
346-
```go
374+
375+
```yag
347376
{{$builder1 := componentBuilder}}
348377
{{$builder2 := componentBuilder}}
349378
{{$oven := cslice
@@ -362,19 +391,23 @@ Combine another builder into the current one.
362391
```
363392

364393
### componentBuilder.Get
394+
365395
Retrieve components stored under a key.
366396

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

370400
- Example:
371-
```go
401+
402+
```yag
372403
{{$textComponents := $builder1.Get "text"}}
373404
```
405+
374406
`$textComponents` now contains the ingredient and oven text slices.
375407

376408
### Example (With helper functions)
377-
```go
409+
410+
```yag
378411
{{$section := sdict
379412
"text" "🍲 **Lasagna Recipe**"
380413
"button" (cbutton (sdict "label" "Set Servings" "custom_id" "set-servings" "style" "primary"))

content/docs/reference/templates/functions.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ Components V2 introduces a new way to create interactive and visually appealing
790790
```yag
791791
{{ $component := componentBuilder (sdict [text] [section] [gallery] [file] [separator] [container] [buttons] [menus] [interactive_components] [allowed_mentions] [reply] [silent] [ephemeral])}}
792792
```
793+
793794
Returns a complex message object with the given components.
794795

795796
All keys are optional, but the Discord API will reject completey empty messages, so some content is required.
@@ -837,6 +838,7 @@ The `ComponentBuilder` object provides methods to construct, manipulate, and exp
837838
#### ComponentBuilder.Add
838839

839840
Adds a single component entry to the builder under the given key.
841+
840842
```yag
841843
{{ $builder := componentBuilder }}
842844
{{ $builder.Add "key" "value" }}
@@ -846,7 +848,9 @@ Adds a single component entry to the builder under the given key.
846848
- `value` – The component data (string, sdict, Button, SelectMenu, etc.).
847849

848850
#### ComponentBuilder.AddSlice
851+
849852
Adds multiple components under one key.
853+
850854
```yag
851855
{{ $builder := componentBuilder }}
852856
{{ $builder.AddSlice "key" (cslice "value1" "value2" "value3") }}
@@ -856,24 +860,30 @@ Adds multiple components under one key.
856860
- `values` – The component data (string, sdict, Button, SelectMenu, etc.).
857861

858862
#### ComponentBuilder.Merge
863+
859864
Combine another builder into the current one.
865+
860866
```yag
861867
{{ $builder1 := componentBuilder }}
862868
{{ $builder2 := componentBuilder }}
863869
{{ $builder1.Merge $builder2 }}
864870
```
871+
865872
- `other` – The builder to merge.
866873

867874
#### ComponentBuilder.Get
875+
868876
Returns the component data for the given key.
877+
869878
```yag
870879
{{ $builder := componentBuilder }}
871880
{{ $builder.Add "key" "value" }}
872881
{{ $value := $builder.Get "key" }}
873882
```
883+
874884
- `key` – The top-level key for the component (e.g., "text", "section", "buttons").
875885

876-
Example usage can be found at the [Components v2](../components-v2.md).
886+
Example usage can be found at the [Components v2](/docs/reference/components-v2).
877887

878888
---
879889

0 commit comments

Comments
 (0)