# Custom embed codes

Source: https://righteousbot.dev/docs/features/embed-codes/

The one embed-code language (tags, variables, buttons and ++delete) used in welcome messages, tickets, level-ups and everywhere else Righteous asks for one.

An embed code is plain text with `{tag: value}` chunks in it, separated by `$p`. Every surface that
takes one speaks this same language: see [where a code works](#know-where-a-code-works). To try one
without saving it, use the [embed builder](/docs/embeds/) (a live preview that sends nothing) or
[`,customembed`](/commands/server-tools/customembed/#customembed-create) (`,ce`, **Manage Messages**).
Each surface has its own permission, usually **Manage Server**.

## Post a code and see what you get [#post-a-code-and-see-what-you-get]

Text outside any tag is plain message text. Add tags and the same command posts an embed. Order
doesn't matter: tags are found by name.

<CommandBlock syntax=",customembed <code>" example=",customembed {title: Announcement}$p{description: Doors open at 8.}$p{color: #fb4868}" />

<EmbedPreview code="{title: Announcement}$p{description: Doors open at 8.}$p{color: #fb4868}" caption="A title, a line of body text, and the colored stripe down the left." />

[`,copyembed <message link>`](/commands/server-tools/copyembed/#copyembed) turns an existing message
back into its code. Right-click it, then **Apps → Copy Embed Code**, does the same. It also copies a
[Components V2](#switch-the-whole-message-to-components-v2) card (as a `{v2:}` code) and a forwarded
message. A reply button keeps its reply only if it is one of Righteous's own reply buttons, the message
is from your own server and the reply is still there (a now-playing reply lasts 1 hour). Anything a code
can't hold is listed under the copy.

## Build the embed out of tags [#build-the-embed-out-of-tags]

| Tag                              | Sets                                                        | Takes                    |
| -------------------------------- | ----------------------------------------------------------- | ------------------------ |
| `{title: text}`                  | the heading                                                 | text                     |
| `{description: text}`            | the body                                                    | text                     |
| `{color: value}`                 | the left stripe                                             | a hex color, or `random` |
| `{url: link}`                    | makes the title a link                                      | an http(s) link          |
| `{thumbnail: link}`              | the small image, top right                                  | an image link            |
| `{image: link}`                  | the large image, bottom                                     | an image link            |
| `{author: name && icon && link}` | the line above the title                                    | name required            |
| `{footer: text && icon}`         | the line at the bottom                                      | text required            |
| `{field: name && value}`         | a labelled block; add `&& inline` to sit it beside the next | both required            |
| `{timestamp:}`                   | a time on the footer                                        | nothing                  |
| `{content: text}`                | text outside the embed (loose text does the same)           | up to 2,000 characters   |
| `{button: ...}`                  | a button under the message                                  | [below](#add-buttons)    |

* A second `{title:}` is ignored; several `{content:}` tags add up in order.
* Multi-part tags split on `&&`, so a name, footer or label can't contain one. `{field:}` keeps
  everything after the first `&&` as its value.
* A chunk that looks like a tag but isn't (`{banner: x}`) is dropped silently, so a misspelling gives
  you nothing, not an error. An unreadable `{color:}` falls back to black.

## Fill in names and numbers with variables [#fill-in-names-and-numbers-with-variables]

Variables go inside a tag and fill in when the message sends, like `{description: {user.mention} is member number {guild.membercount}.}`. Every token is on the [variables page](/docs/variables/), or run
[`,customembed variables`](/commands/server-tools/customembed/#customembed-variables). &#x2A;*Which ones
fill in depends on where the code runs:**

| Tokens                                                                  | Work                                                                                |
| ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `{user.*}`, `{guild.*}`, `{channel.name}`, `{color.random}`             | anywhere                                                                            |
| `{ticket.*}`                                                            | only in a ticket greeting                                                           |
| `{level}`, `{xp.into}`, `{rank}`, `{reward}`                            | only in a [`,levels embeds`](/commands/levels/levels/#levels-embeds) message        |
| `{track.*}`, `{album.*}`, `{artist.*}`, `{spotify.*}`, Rotation ratings | where the member has a linked Last.fm account (ratings also need a linked Rotation) |

An unknown token or a misspelling (`{usr}`) renders as **its own name**, braces dropped. That's why
`{ticket.id}` on the ticket *panel* shows the bare words `ticket.id`. Only the Last.fm and Rotation
tokens render as nothing, for a member with no account or no scrobble.

## Add buttons [#add-buttons]

<CommandBlock syntax=",customembed <code>" example=",customembed {description: Read these first.}$p{button: Rules && https://example.com/rules}" />

<EmbedPreview code="{description: Read these first.}$p{button: Rules && https://example.com/rules}" caption="A link button under the message." />

| Part       | Means                                            | Example               |
| ---------- | ------------------------------------------------ | --------------------- |
| label      | the button text                                  | `Rules`               |
| link       | where it sends people                            | `https://example.com` |
| emoji      | unicode, or one of your server's as `<:name:id>` | `🎧`                  |
| color      | `link`, `blue`, `green`, `grey` or `red`         | `green`               |
| `disabled` | greys it out                                     | `disabled`            |

Parts are matched by kind, in any order. A label or an emoji is required. You get up to 25 buttons,
five to a row, and one the parser can't build is dropped while the rest sends. &#x2A;*Link buttons open
their link.** A colored button does nothing on its own, unless you give it a
[private reply](#answer-a-button-with-a-private-reply).

## Answer a button with a private reply [#answer-a-button-with-a-private-reply]

End a colored button with `&& reply:` and a whole embed code, and whoever presses it gets that code as a
message only they can see.

<CommandBlock syntax=",customembed <code>" example=",customembed {title: Rules}$p{button: blue && Read me && reply: {title: Hi {user.name}}$p{description: Be kind and keep chat on topic.}}" />

<EmbedPreview surface="message" code="{title: Rules}$p{button: blue && Read me && reply: {title: Hi {user.name}}$p{description: Be kind and keep chat on topic.}}" caption="Press Read me: the reply appears under the message, and only the person who pressed it sees it in Discord." />

* **Where it works:** welcome, goodbye, boost and unboost messages, join DMs, sticky messages,
  [`,pages`](/commands/server-tools/pages/#pages-add) (button mode only: a page set flipped with reactions can't show them), `,customembed` and `,editembed`, ticket greetings and
  the ticket panel, and [now-playing layouts](/docs/lastfm/now-playing/#add-reply-buttons). **Everywhere else
  the bot removes the reply** and the button does nothing, [`,webhooks send`](/commands/server-tools/webhooks/#webhooks-send) included.
* **On those messages the reply lasts as long as the message does,** restarts included, and it is filled in
  for **whoever presses it**: `{user.name}` is the person who pressed, and Last.fm variables are theirs.
  A now-playing reply is different: a snapshot of the song when the card posted, kept for 1 hour.
* **Ticket variables (`{ticket.*}`) don't work inside a reply.**
* **A server can keep 500 replies.** Past that, a save that adds a new one is refused; the ones you
  have keep working. The same reply on many messages counts once. Custom embeds (`,customembed`,
  `,editembed`) can use up to 100 of the 500.
* `reply:` goes **last**, up to **5** reply buttons per code, and a link button can't have one.
* The preview in the builder and in the add commands shows the button, but it only answers once the
  code is saved.

## Change how a variable prints [#change-how-a-variable-prints]

Wrap a variable's name in a function to change its text: `{upper(track.name)}`, `{lower(user.name)}` or
`{proper(user.plays)}`.

| Function      | Does                                                                  | Example                |
| ------------- | --------------------------------------------------------------------- | ---------------------- |
| `{lower(x)}`  | lowercases it                                                         | `{lower(user.name)}`   |
| `{upper(x)}`  | uppercases it                                                         | `{upper(track.name)}`  |
| `{proper(x)}` | adds thousands separators to a number; text such as `?` is left alone | `{proper(user.plays)}` |

<CommandBlock syntax=",customembed <code>" example=",customembed {description: {upper(user.name)} has {proper(user.plays)} scrobbles.}" />

<EmbedPreview code="{description: {upper(user.name)} has {proper(user.plays)} scrobbles.}" caption="The name in capitals, the count with commas." />

They work on Discord and Last.fm variables, in every code. They don't work on ticket (`{ticket.*}`) or
level-up (`{level}`, `{xp.*}`) variables, and one function can't wrap another.

## Delete the message after a while [#delete-the-message-after-a-while]

`++delete` is an action, not a tag. It never renders and goes at the very end of the code.

<CommandBlock syntax=",customembed <code> ++delete <seconds>" example=",customembed {description: Back in five.} ++delete 30" />

What it takes depends on where you write it:

| Where                                                                                                 | Takes                                         | Default |
| ----------------------------------------------------------------------------------------------------- | --------------------------------------------- | ------- |
| `,customembed`, [`,webhooks send`](/commands/server-tools/webhooks/#webhooks-send), a ticket greeting | whole seconds, 1 to 600                       | off     |
| `,welcomemessage add` and its goodbye, boost and unboost twins                                        | whole seconds, 1 to 60                        | off     |
| `,levels embeds`                                                                                      | a duration up to `1h` (`30s`, `5m`), or `off` | off     |

`++delete 30` is an error on the last row, which wants `30s`; `++delete 1h` is refused on the first.

<Callout type="warn" title="Put the flag last">
  Every surface reads `++delete` only at the very end of the code. The welcome, goodbye, boost and
  unboost commands refuse a value they can't read (`++delete 1h`, or `6O` with a letter O) instead of
  guessing.
</Callout>

**Four surfaces ignore the timer** (the flag is still stripped): join DMs and trap DMs, because a DM
may not have been opened yet, and [`,pages`](/commands/server-tools/pages/#pages-add) and
[`,editembed`](/commands/server-tools/editembed/#editembed), which edit a message that already
exists. On server and level-up messages the value is saved as that message's own setting: see
[server messages](/docs/features/server-messages/).

## Switch the whole message to Components V2 [#switch-the-whole-message-to-components-v2]

`{v2:}` anywhere renders a Components V2 container instead of an embed. Same `$p`, variables and
buttons, plus three tags:

<CommandBlock syntax=",customembed <code>" example=",customembed {v2:}$p{title: New here?}$p{gallery: https://example.com/a.png && https://example.com/b.png}$p{separator:}$p{section: Start in the rules channel && https://example.com/icon.png}" />

| Tag                            | Adds                                                               |
| ------------------------------ | ------------------------------------------------------------------ |
| `{gallery: link && link …}`    | up to ten images in one grid                                       |
| `{section: text && accessory}` | text beside a thumbnail (one image link) *or* a button, never both |
| `{separator:}`                 | a divider line                                                     |

Only the first `{section:}` and one `{separator:}` render, in a fixed order (text, gallery,
section, separator, buttons). Author and footer icons and inline fields are dropped. The text budget
is 4,000 characters, against 6,000 for an embed; past it, a send falls back to a classic embed
without the gallery, section and separator.

<Callout type="error" title="Two places V2 doesn't work">
  [`,webhooks send`](/commands/server-tools/webhooks/#webhooks-send) refuses a `{v2:}` code. In
  [`,pages`](/commands/server-tools/pages/#pages-add) a `{v2:}` page saves cleanly into a
  single-page set, reports success, then never renders. Keep page sets classic.
</Callout>

## Know where a code works [#know-where-a-code-works]

| Where                                         | Set with                                                                                                                              |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| Welcome, goodbye and boost messages, join DMs | [Server messages](/docs/features/server-messages/)                                                                                    |
| Punishment confirmations (Server Premium)     | [`,custommessage`](/commands/server-tools/custommessage/#custommessage)                                                               |
| Ticket greetings and panel                    | [`,ticket message`](/commands/server-tools/ticket/#ticket-message), [`,ticket setup`](/commands/server-tools/ticket/#ticket-setup)    |
| Level-up announcements                        | [`,levels embeds`](/commands/levels/levels/#levels-embeds)                                                                            |
| Sticky messages (Server Premium)              | [`,stickymessage add`](/commands/server-tools/stickymessage/#stickymessage-add)                                                       |
| A paginated set of embeds                     | [`,pages add`](/commands/server-tools/pages/#pages-add)                                                                               |
| Trap channel DMs                              | [`,trap dm`](/commands/server-tools/trap/#trap-dm), [Trap channel](/docs/protection/trap-channel/)                                    |
| A one-off webhook message                     | [`,webhooks send`](/commands/server-tools/webhooks/#webhooks-send)                                                                    |
| Your now-playing card (Self Premium)          | [`,lastfm mode`](/commands/lastfm/lastfm/#lastfm-mode)                                                                                |
| A one-off post, or editing one you sent       | [`,customembed`](/commands/server-tools/customembed/#customembed-create), [`,editembed`](/commands/server-tools/editembed/#editembed) |

<Callout type="error" title="Autoresponders do not take embed codes">
  [`,autoresponder`](/commands/server-tools/autoresponder/#autoresponder-add) replies get variables
  only. `{title: Hi}` posts as literal text, and there is no embed or button. `++delete` is the one
  flag they take.
</Callout>

## Common issues [#common-issues]

**Nothing posted.** Every tag is misspelled, so the message is empty and Discord won't take it. Try a
bare `{description: test}`.

**A tag printed as visible text.** You're on a surface that doesn't parse codes, usually the
autoresponder.

**A word from my code shows up bare.** A misspelled token, or one used outside its surface (see the
table above). Check the [variables page](/docs/variables/). A token that comes out **empty** is a
Last.fm one: no linked account or nothing scrobbled.

**A line like `Notice: read this` vanished.** It looks like a mistyped tag. Wrap it:
`{content: Notice: read this}`.

**A `{v2:}` page saved but the paginator shows the old one.** Discord can't turn a classic embed into
a V2 container. Put the page back to classic tags.

**Nothing here fixed it.** The shared [common issues](/docs/common-issues/) page works from the
symptom end.
