-
Notifications
You must be signed in to change notification settings - Fork 17
component v2 Docs #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
c5637e5
35c2211
3f6ea5b
ebd9872
8bdee5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
```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). | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
- `thumbnail`: A sdict with the following keys: | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
- `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) | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
- `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). | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
- `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 | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.