@@ -781,6 +781,112 @@ object](/docs/reference/templates/syntax-and-data#message). Is also valid for ep
781
781
782
782
---
783
783
784
+ ## Component V2
785
+
786
+ Components V2 provides a new way to create interactive and visually appealing message layouts in Discord applications,
787
+ making it easier to control message formatting and user interaction while maintaining line length under 120 characters.
788
+
789
+ ### componentBuilder
790
+
791
+ A ` componentBuilder ` simplifies building Discord's ComponentsV2 in custom commands.
792
+
793
+ ``` yag
794
+ {{ $component := componentBuilder (sdict [text] [section] [gallery] [file] [separator] [container] [buttons] [menus] [interactive_components] [allowed_mentions] [reply] [silent] [ephemeral]) }}
795
+ ```
796
+
797
+ Returns a complex message object with the given components.
798
+
799
+ All keys are optional, but the Discord API will reject completey empty messages, so some content is required.
800
+
801
+ - ` text ` : A string or a slice of strings.
802
+ - ` section ` : A layout block that shows text with one optional accessory: a button ** or** a thumbnail with the following keys:
803
+ - ` text ` : A string or a slice of strings.
804
+ - ` button ` : A [ button object] ( #cbutton ) .
805
+ - ` thumbnail ` : An sdict with the following keys:
806
+ - ` media ` : A string.
807
+ - ` description ` : A string.
808
+ - ` spoiler ` : A bool.
809
+ - ` gallery ` : Displays one or more media items with optional descriptions and spoiler flags with the following keys:
810
+ - ` media ` : A string.
811
+ - ` description ` : A string.
812
+ - ` spoiler ` : A bool.
813
+ - ` file ` : Attaches text files to the message and optionally displays them with the following keys:
814
+ - ` content ` : A string. (max 100 000 chars)
815
+ - ` name ` : A string. (.txt appended automatically)
816
+ - ` separator ` : Adds spacing between components with the following keys:
817
+ - ` true ` : large separator
818
+ - ` false ` or ` nil ` : small separator
819
+ - ` container ` : Top-level layout. Containers offer the ability to visually encapsulate a collection of components,
820
+ and have an optional customizable accent color bar. Contains the following keys:
821
+ - ` components ` : A [ componentBuilder] ( #componentbuilder ) or a slice thereof.
822
+ - ` color ` : hex accent color (optional).
823
+ - ` spoiler ` : hides content until revealed (optional).
824
+ - ` buttons ` : Interactive [ buttons] ( #cbutton ) users can click. Can be single or multiple.
825
+ - ` menus ` : Interactive [ menus] ( #cmenu ) s users can select from. Can be single or multiple.
826
+ - ` interactive_components ` : Mix of buttons and menus, auto-distributed.
827
+ - ` allowed_mentions ` : A sdict with the following keys:
828
+ - ` users ` : A slice of user IDs.
829
+ - ` roles ` : A slice of role IDs.
830
+ - ` everyone ` : A bool.
831
+ - ` replied_user ` : A bool.
832
+ - ` reply ` : A sdict with the following keys:
833
+ - ` message_id ` : A string.
834
+ - ` thread_id ` : A string.
835
+ - ` silent ` : A bool.
836
+ - ` ephemeral ` : A bool.
837
+
838
+ ### Component Builder Functions
839
+
840
+ The ` ComponentBuilder ` simplifies building Discord's V2 components, allowing complex layouts to be built incrementally.
841
+ It provides methods for constructing, manipulating, and exporting components in a format Discord understands,
842
+ ensuring line length doesn't exceed 120 characters.
843
+
844
+ #### ComponentBuilder.Add
845
+
846
+ Adds a single component entry to the builder under the given key.
847
+
848
+ ``` yag
849
+ {{ $builder.Add <key> <value> }}
850
+ ```
851
+
852
+ - ` key ` – The top-level key for the component (e.g., "text", "section", "buttons").
853
+ - ` value ` – The component data (string, sdict, Button, SelectMenu, etc.).
854
+
855
+ #### ComponentBuilder.AddSlice
856
+
857
+ Adds multiple components under one key.
858
+
859
+ ``` yag
860
+ {{ $builder.AddSlice <key> <values...> }}
861
+ ```
862
+
863
+ - ` key ` – The top-level key for the component (e.g., "text", "section", "buttons").
864
+ - ` values ` – The component data (string, sdict, Button, SelectMenu, etc.).
865
+
866
+ #### ComponentBuilder.Merge
867
+
868
+ Combine another builder into the current one.
869
+
870
+ ``` yag
871
+ {{ $builder.Merge <other> }}
872
+ ```
873
+
874
+ - ` other ` – The other component builder to merge.
875
+
876
+ #### ComponentBuilder.Get
877
+
878
+ Returns the component data for the given key.
879
+
880
+ ``` yag
881
+ {{ $value := <builder>.Get <key> }}
882
+ ```
883
+
884
+ - ` key ` – The top-level key for the component (e.g., "text", "section", "buttons").
885
+
886
+ Example usage can be found at the [ Components v2] ( /docs/reference/components-v2 ) .
887
+
888
+ ---
889
+
784
890
## Math
785
891
786
892
#### abs
0 commit comments