Skip to content

Commit 8137ddb

Browse files
authored
docs/reference: amend custom embeds docs (#74)
Correct link to discord message docs Document YAML usage Give a more complex example with footer text instead of description Add unicode escape sequence to escape table Replace example image to reflect new examples in both YAML and JSON Link to Wikipedia pages for YAML/JSON syntax -- we only have a (very) simplified/incomplete description here Reword existing usage docs Signed-off-by: Galen CC <[email protected]>
1 parent c535221 commit 8137ddb

File tree

2 files changed

+59
-31
lines changed

2 files changed

+59
-31
lines changed

content/docs/reference/custom-embeds.md

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ documentation](https://discord.com/developers/docs/resources/channel#embed-objec
1717

1818
{{< callout context="note" title="Note: Custom Commands use Custom Syntax" icon="outline/info-circle" >}}
1919

20-
Custom Embeds with the `-customembed` command don't work in custom commands. If you want to know how you can use embeds
20+
Custom Embeds with the `customembed` command don't work in custom commands. If you want to know how you can use embeds
2121
in custom commands, scroll down to [Embeds in Custom Commands](#embeds-in-custom-commands).
2222

2323
{{< /callout >}}
@@ -28,56 +28,84 @@ One method of sending an embed with YAGPDB is using the command `customembed` (o
2828

2929
### Create embeds by hand
3030

31-
YAGPDB accepts embeds in JSON following the rules of Discord's [Embed Object] structure.
31+
YAGPDB accepts embeds in JSON or YAML following the rules of Discord's [Embed Object] structure.
3232

33-
[Embed Object]: https://discord.com/developers/docs/resources/message#embed-object.
33+
[Embed Object]: https://discord.com/developers/docs/resources/message#embed-object
3434

35-
```javascript
36-
{ "title": "This is my title", "description": "This is my description." }
35+
![An Example of the Custom Embed Command](custom_embed_example.png)
36+
37+
#### Using YAML
38+
39+
```yaml
40+
title: This is my title
41+
footer:
42+
text: This is my footer text.
3743
```
3844

39-
The output of this would look like the following:
45+
YAML input is formatted as a list of names with associated values for each part of the embed. In this example I start
46+
with a name (title) and the associated value (This is my title) after a semicolon. On a new line, we have another name
47+
(footer), this time with another list of name-value pairs as the value. An indent indicates that the name-value pair
48+
(text: This is ...) is part of the value of the footer.
4049

41-
![An Example of the Custom Embed Command](custom_embed_example.png)
50+
##### The syntax of YAML
51+
52+
[YAML] has an intuitive, lenient syntax. Most parts of the embed are simple name-value pairs (or nested name-value
53+
maps like in the footer shown above). New lines separate each pair, unless the next line is indented to indicate that
54+
that line is the value. Strings (text) can be included as-is without quotes, unless the text contains special characters
55+
like `:`, in which case single quotes (`'`) or double quotes (`"`) may be used. Double quotes allow backslash-escapes to
56+
add newlines, double quotes, and more.
57+
58+
[YAML]: https://en.wikipedia.org/wiki/YAML#Syntax
59+
60+
#### Using JSON
61+
62+
```javascript
63+
{ "title": "This is my title", "footer": { "text": "This is my footer text." } }
64+
```
65+
66+
As shown in the example above, I start my object (the embed) with a curly brace. Like YAML, we then have a name (title)
67+
and the value for that name (This is my title). We separate each name-value pair with a comma. Then we have something
68+
similar, but with another object as the value. Within that object we have a name-value pair with the same format as the
69+
title, this time for the footer text. In the end we close the objects (footer and embed) with more curly braces.
4270

43-
Let's break this down: We start of with the customembed command `-ce`. After this, I start my object (the embed) with a
44-
curly brace. Then we have the name of the object (title) and the value of it (This is my title). We separate data with
45-
commas. After that we have the same thing again, but for the description. In the end we close the object (embed) with
46-
another curly brace.
71+
##### The syntax of JSON
4772

48-
You can add the multiple objects to this, but keep in mind that Discord limits your message to 2000 characters.
73+
[JSON]'s syntax is also quite simple. Objects start with an opening curly brace (`{`) and end with a closing curly brace
74+
(`}`). Between these, you can add names and their associated values. Each name-value pair is separated by a comma (`,`).
75+
Around strings (text) you wrap two quotation marks (`""`), but nothing around integers (whole numbers) or booleans
76+
(`true` or `false` values). You can play around with this a bit.
4977

50-
#### The syntax of JSON
78+
Some special characters need to be prefixed with a backslash in strings to indicate that they aren't part of the JSON
79+
syntax:
5180

52-
The syntax of json is pretty easy. You start off with a curly brace (`{`) and end with a curly brace (`}`). Between
53-
this, you can add names and their according values. Data (a name and a value) get separated by commas (`,`) . Around
54-
strings (text) you wrap two quotation marks (`""`), but nothing around integers (whole numbers) or booleans (true or
55-
false statements). You can play around with this a bit.
81+
| Special character | Escaped input |
82+
| ------------------ | ------------- |
83+
| Quotation mark (") | \\" |
84+
| Backslash (\\) | \\\\ |
85+
| Slash (/) | \\/ |
86+
| Backspace | \b |
87+
| Form feed | \f |
88+
| New line | \n |
89+
| Carriage return | \r |
90+
| Horizontal tab | \t |
91+
| [Unicode character] | \uXXXX |
5692

57-
| Special character | Escaped output |
58-
| ------------------ | -------------- |
59-
| Quotation mark (") | \\" |
60-
| Backslash (\\) | \\\\ |
61-
| Slash (/) | \\/ |
62-
| Backspace | \b |
63-
| Form feed | \f |
64-
| New line | \n |
65-
| Carriage return | \r |
66-
| Horizontal tab | \t |
93+
[JSON]: https://en.wikipedia.org/wiki/JSON#Syntax
94+
[Unicode character]: https://en.wikipedia.org/wiki/List_of_Unicode_characters
6795

6896
### Create embeds with a generator
6997

7098
Creating embeds with a generator can be more difficult if you don't need any difficult features. If you want your embed
71-
to be super shiny, you can use [this embed generator](https://leovoel.github.io/embed-visualizer/). YAGPDB does not use
72-
the first part of its code, so you have to remove the following:
99+
to be super shiny, you can use [an embed generator](https://leovoel.github.io/embed-visualizer/). The customembed
100+
command only sends an embed, so you'll need to remove everything around it:
73101

74102
````javascript
75103
{
76-
"content": "this `supports` __a__ **subset** *of* ~~markdown~~ 😃 ```js\nfunction foo(bar) {\n console.log(bar);\n}\n\nfoo(1);```",
104+
"content": "...",
77105
"embed":
78106
````
79107

80-
and the last curly brace (`}`). After this you can just copy and paste it into Discord:
108+
and the last curly brace (`}`). After this you can copy and paste it after the `ce` command:
81109

82110
![Result of the Embed Generator](embed_generator_result.png)
83111

-10.2 KB
Loading

0 commit comments

Comments
 (0)