Custom Embeds

An embed is just like a form, containing many objects, such as the Title, the Author, the Thumbnail, the Description, the Fields, the Color, the Footer, the Image, the URL, and the Timestamp

The customembed command

One method of sending an embed with YAGPDB is using the command customembed (or for short, ce).

Create embeds by hand

YAGPDB accepts embeds in JSON following the rules of this format.

There, we'll take a look at the Embed Objects. You can add a value to each of these objects. A very simple embed would look like this:

{ "title": "This is my title", "description": "This is my description." }

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

You can add the multiple objects to this, but keep in mind that Discord limits your message to 2000 characters.

The syntax of JSON

The syntax of json is pretty easy. You start off with a curly brace ({) and end with a curly brace (}). Between this, you can add names and their according values. Data (a name and a value) get separated by commas (,) . Around strings (text) you wrap two quotation marks (""), but nothing around integers (whole numbers) or booleans (true or false statements). You can play around with this a bit.

Special character

Escaped output

Quotation mark (")

\"

Backslash (\)

\\

Slash (/)

\/

Backspace

\b

Form feed

\f

New line

\n

Carriage return

\r

Horizontal tab

\t

Creating embeds with a generator can be more difficult if you don't need any difficult features. If you want your embed to be super shiny, you can use this embed generator. YAGPDB does not use the first part of its code, so you have to remove the following:

{
  "content": "this `supports` __a__ **subset** *of* ~~markdown~~ 😃 ```js\nfunction foo(bar) {\n  console.log(bar);\n}\n\nfoo(1);```",
  "embed": 

and the last curly brace (}). After this you can just copy and paste it into Discord:

The simpleembed command

Simple embeds are easier to use than custom embeds as they do not require any knowledge of json. Their downside is that they don't support all Discord embed fields from the embed structure, for example fields. You can create a simple embed with the simpleembed command, se for short.

Simple embeds work with switches, here is a list of them all:

Switch

Description

-channel

Optional channel to send in.

-title

Title field.

-desc

Description field.

-color

Color field, either in hex or a color name.

-url

URL field for embed.

-thumbnail

URL to an image for thumbnail field.

-image

URL to an image.

-author

Author field.

-authoricon

URL for the icon in 'author' field.

-footer

Footer field.

-footericon

URL to an image for footer icon field.

The values for simple embeds need to bet placed within quotes:

-se -title "This is my title" -desc "This is my description" -thumbnail "https://via.placeholder.com/300/"

You can play around with this command a bit because it's really easy to use.

Simple embeds can be used in custom commands:{{execAdmin "se" "-desc" "This is my description"}}

Embeds in Custom Commands

Preface

Look at the following embed, is it beautiful? Most of the people will say "yes". So, how can you create an embed like that in custom commands?

Read the following codes, and you will notice that the codes for the embed are not very different from the normal custom commands. That being so, there are still some differences between them.

{{$avatar := (joinStr "" "https://cdn.discordapp.com/avatars/" (toString .User.ID) "/" .User.Avatar ".png") }}

{{$embed := cembed 
"title" (joinStr " " "📢 Hello there, "  .User.Username "!") 
"description" "Welcome to **__Google Classroom__**. We are glad to see you!" 
"color" 4645612 
"fields" (cslice
    (sdict "name" "Tip" "value" "If you want, you can click this link to see the docs: https://yusuftseng.gitbook.io/yagpdb/" "inline" false)
    (sdict "name" "Advice" "value" (joinStr " " (execAdmin "Advice")) "inline" false)
    (sdict "name" "Advice" "value" (joinStr " " (execAdmin "Topic")) "inline" false)
    (sdict "name" "Advice" "value" (joinStr " " (execAdmin "catfact")) "inline" false)
    (sdict "name" "Advice" "value" (joinStr " " (execAdmin "dogfact")) "inline" false)
    (sdict "name" "Member Count" "value" (joinStr " " (toString .Guild.MemberCount) "<:MEE6_happy:639094722425651210>") "inline" true) 
    (sdict "name" "Member Name" "value" (joinStr " " .User.Mention "<:MEE6_ghost:639094722429976597>") "inline" true) 
    (sdict "name" "Member ID" "value" (joinStr " " (toString .User.ID) "<:mice:684225165315407872>") "inline" true)) 
"thumbnail" (sdict "url" $avatar) 
"footer" (sdict "text" "Thanks for joining our server") 
"timestamp" (currentTime.Add 0) }}
{{sendMessage nil $embed}}

Do you think that making an embed is hard? After reading the content below, you will be able to make your own unique embed by yourself.

Now we are going to introduce how to make an embed with YAGPDB in a custom command.

Create an embed

When you create an embed by a custom command, cembed is indispensable. There are several ways of making and sending an embed. We will introduce some below.

  • Create an embed, save it into a normal variable, and send a message with that variable.

{{$embed := cembed "title" "This is my title" "description" "This is my description"}}
{{sendMessage nil $embed}}
  • Directly use sendMessage with the message being cembed ....

{{sendMessage nil (cembed "title" "This is my title" "description" "This is my description")}}
  • Save the embed into a variable ($s for example) which is of type templates.SDict, use cembed $s to create an embed, and send it with sendMessage.

{{$s := sdict "title" "This is my title" "description" "This is my description"}}
{{sendMessage nil (cembed $s)}}

Title and Description

The basic objects of an embed.

"title" "This is my title" "description" "This is my description."

We don't follow the json syntax here and only define everything one after the other ("name" "value" et cetera). Now we use the objects for discord embeds from the developer page.

The title will be added as if it added `` around itself, so you cannot mention things, display an emoji, use * around the words to display special things, etc.

You can also add a link to the title to make it a hyperlink (you can change the link to any valid link you want).

"url" "https://cdn.discordapp.com/attachments/739389991603404860/756514150217416794/cat_hug.gif"

The followings introduce more things that you can add in an embed.

Add fields

"fields" (cslice 
    (sdict "name" "Title of field 1" "value" "Description of field 1" "inline" false) 
    (sdict "name" "Title of field 2" "value" "Description of field 2" "inline" false)
    ......
    More fields can be written here 
    ......
    (sdict "name" "After the last field" "value" "You should add a `)` to close the `cslice` function" "inline" false))

If you set inline to true, they would try to get displayed next to each other. You can add multiple fields with sdict.

Display an image

You can display an image by simply pasting the link to it in the response, or by doing it fancy this way: (make sure to replace the link with your own image)

"image" (sdict "url" "https://i.imgur.com/ttIwOmn.png")

Add author objects

You can add the author in the embed, and his/her avatar or any image as well.

{{/*Only add the name of the author*/}}
"author" (sdict "name" "Me")

{{/*Add the avatar as well*/}}
"author" (sdict "name" .User.String "icon_url" (.User.AvatarURL "64"))

{{/*Add things you want*/}}
"author" (sdict "name" "Hi" "icon_url" "https://cdn.discordapp.com/attachments/739389991603404860/756492461261455410/on_the_road_---_by_Donut.png")

In the author part, you cannot mention things, display an emoji, use * around the words to display special things, etc.

Display the thumbnail

You can add a thumbnail for the embed to make your embed more beautiful.

"thumbnail" (sdict "url" "https://media.discordapp.net/attachments/166207328570441728/748132842235494480/V0sQwfC.gif")

You can add the footer to show some tips or whatever you want. You can also add an icon for the footer.

{{/*Normal footer*/}}
"footer" (sdict "text" "Hello I am the author of this embed.")

{{/*Display the footer and a picture*/}}
"footer" (sdict "text" "Hello I am the author of this embed." "icon_url" "https://cdn.discordapp.com/emojis/684225165315407872.png?v=1")

The text in the footer will be added as if it added `` around itself, so you cannot mention things, display an emoji, use * around the words to display special things, etc. To be honest, the name of it implies that it can only display text instead of special contents.

The Color of The Embed

You can add color (decimal number) for your embed to make it better.

"color" 16777214

Discord uses color decimal. SpyColor is a good tool to pick colors or convert hex to decimal. Visit there or use the following command to convert hex to decimal.

{{with (lower (reFind `^[0-9a-fA-F]{1,6}$` (joinStr " " .CmdArgs)))}}
    {{$h := .}}{{$z := 0}}{{$e := 0}}
    {{$lenHex := len . | mult -1 | add 1}}
    {{range $k, $kk := seq $lenHex 1}}
        {{/*Indexing array it's ASCII codes get proper value*/}}
        {{if not $e}}
            {{$v := index $h $k}}
            {{$a := ""}}
            {{if and (ge $v 48) (le $v 57)}}
            {{$a = printf "%c" $v}}
            {{else if and (ge $v 97) (le $v 102)}}{{$a = add $v -87}}{{else}}{{$e = 1}}{{end}}
            {{/*The equation for calc is formed here*/}}
            {{$kk = mult $kk -1}}
            {{$z = joinStr "" $z "+" $a "*16^" $kk}}
        {{end}}
    {{end}}
    {{/*Using calc*/}}
    {{with $z}}
        {{joinStr "" "Hex: " $h " in Decimal: " (reFind `\d+` (exec "calc" .))}}
    {{end}}
{{else}}
    Error, argument needs to be RGB hex in length of 6 characters eg 89aa00.
{{end}}

Use Sdict to Create an Embed

If a value inside an embed is from your input, how to make it?

Compare the two ways written below:

Condition: If you input something $s after the trigger -e, it will make the description for the embed.

  • Without sdict:

{{$embed := ""}}
{{if .CmdArgs}}
{{$embed = cembed "title" "Hi" "description" "Input"}}
{{else}}
{{$embed = cembed "title" "Hi"}}
{{end}}
{{sendMessage nil $embed}}

This way is for novices, and it will waste lots of space, so we don't really recommend this way.

  • With sdict:

{{$embed := sdict "title" "Hi"}}
{{if .CmdArgs}}
{{$embed.Set "description" "Input"}}
{{end}}
{{sendMessage nil (cembed $embed)}}

This way can save much more space than the previous way, especially when there are many objects being made by if-else function. Try to make your own embed with the means above. You can spot that the more complicated your embed is, the more efficient the sdict way is.

Complex Message by Sdict

The following way allows you to use sdict to create a complex message.

{{$message := sdict "content" "Hi" "embed" (sdict "title" "Hi" "description" "Bye") "file" "ez?"}}
{{sendMessage nil (complexMessage $message)}}

Remember that the usage of complexMessage is complexMessage "content" "Your content" "embed" "The embed" "file" "The text file"? So just create 3 keys inside sdict: content, embed, and file, and then make the value of the key embed a sdict that contains the embed objects. Finally, use sendMessage nil (complexMessage $message) to send the complex message.

Edit an Embed

If you want the embed the bot sends to be edited after a while or a specific action, how to do it? sdict will be the best solution to the question.

  • The following command makes the bot send an embed with the title itself only, and edit the embed with more objects after 3 seconds.

{{$embed := sdict "title" "Hi"}}
{{$id := sendMessageRetID nil (cembed $embed)}}
{{sleep 3}}
{{$embed.Set "title" "How are you"}}{{$embed.Set "description" "I am fine, thank you."}}{{$embed.Set "color" 12345678}}
{{editMessage nil $id (cembed $embed)}}

With sdict, we can do way more things than you can think of, so try your best to explore more!

Last updated

Was this helpful?