You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/reference/components-v2.md
+49-16Lines changed: 49 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ description = "Be fancier, use components!"
5
5
+++
6
6
7
7
## componentBuilder
8
+
8
9
`componentBuilder` is a helper for building Discord’s new Components V2 (sections, buttons, menus, galleries, etc.) in YAGPDB custom commands.
9
10
10
11
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
23
24
`text`: string | []string
24
25
25
26
Example:
26
-
```go
27
+
28
+
```yag
27
29
{{$text := componentBuilder (sdict
28
30
"text" "Component Builder v2 test!"
29
31
)}}
@@ -38,6 +40,7 @@ Example:
38
40
)}}
39
41
{{sendMessage nil $text}}
40
42
```
43
+
41
44

42
45
43
46
### Section
@@ -49,7 +52,8 @@ A layout block that shows text with one optional accessory: a button OR a thumbn
49
52
`button`: Button (optional)
50
53
51
54
`thumbnail`: sdict with keys media, description, spoiler (optional)
52
-
```go
55
+
56
+
```yag
53
57
{{$section := componentBuilder (sdict
54
58
"section" (sdict
55
59
"text" "🍲 **Lasagna Recipe**"
@@ -62,9 +66,13 @@ A layout block that shows text with one optional accessory: a button OR a thumbn
@@ -293,20 +314,24 @@ This example combines text, sections, gallery, files, buttons, menus, and contai
293
314
)}}
294
315
{{sendMessage nil $comp}}
295
316
```
317
+
296
318

297
319
298
320
## Component Builder Helper Functions
299
321
300
322
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.
301
323
302
324
### componentBuilder.Add
325
+
303
326
Adds a single component entry to the builder under the given key.
327
+
304
328
- Parameters:
305
329
-`key` – The top-level key for the component (e.g., "text", "section", "buttons").
306
330
-`value` – The component data (string, sdict, Button, SelectMenu, etc.).
307
331
308
332
- Example:
309
-
```go
333
+
334
+
```yag
310
335
{{$builder := componentBuilder}}
311
336
{{$section := sdict
312
337
"text" "🍲 **Lasagna Recipe**"
@@ -316,14 +341,16 @@ Adds a single component entry to the builder under the given key.
316
341
```
317
342
318
343
### componentBuilder.AddSlice
319
-
Adds multiple components under one key.
344
+
A
345
+
dds multiple components under one key.
320
346
321
347
- Parameters:
322
348
-`key` – The top-level key for the component (e.g., "text", "section", "buttons").
323
349
-`values` – The component data (string, sdict, Button, SelectMenu, etc.).
324
350
325
351
- Example:
326
-
```go
352
+
353
+
```yag
327
354
{{$builder := componentBuilder}}
328
355
{{$pasta := cslice
329
356
"### Ingredients"
@@ -337,13 +364,15 @@ Adds multiple components under one key.
337
364
```
338
365
339
366
### componentBuilder.Merge
367
+
340
368
Combine another builder into the current one.
341
369
342
370
- Parameters:
343
371
-`other` – The builder to merge.
344
372
345
373
- Example:
346
-
```go
374
+
375
+
```yag
347
376
{{$builder1 := componentBuilder}}
348
377
{{$builder2 := componentBuilder}}
349
378
{{$oven := cslice
@@ -362,19 +391,23 @@ Combine another builder into the current one.
362
391
```
363
392
364
393
### componentBuilder.Get
394
+
365
395
Retrieve components stored under a key.
366
396
367
397
- Parameters:
368
398
-`key` – The top-level key for the component (e.g., "text", "section", "buttons").
369
399
370
400
- Example:
371
-
```go
401
+
402
+
```yag
372
403
{{$textComponents := $builder1.Get "text"}}
373
404
```
405
+
374
406
`$textComponents` now contains the ingredient and oven text slices.
0 commit comments