Что такое эмбеды в дискорде

Embeds

You've likely seen embeds before. They're a great way to display information to a user in a clean way.

In this section we will cover how to create and customize embeds.

Preview#

Here is an example of what embeds can look like.

Building the Embed#

Discord4J uses Immutable Specs to build objects, for to build embeds we use EmbedCreatSpec.builder() .

Embeds can also be sent when the message contains content:

All embed properties are optional. If you want a simpler embed, you can leave out what you don't want.

Embed Colors#

Discord4J uses a custom Color class when a color param is needed. But, you may want more color choices than the default enum provides.

Blank Fields#

Discord enforces that embed fields and their values contain characters. However, you can "bypass" this restriction by using a zero-width space. To use a ZWS, just use "\u200B" as shown in the example above.

Attaching Images#

Like other messages, images can be directly attached to the message and the embed can use the image from the attachment.

Using attachment://filename.extension as the image URL, an embed can reference the image attached.

If you plan on attaching the same image many times, consider hosting it online and providing the URL to it.

This helps reduce your bandwidth and increase bot response time as you no longer need to upload the image every time its embedded.

Quirks and Features#

  • If you want 2 or more fields side-by-side, they must have inline: true
  • The timestamp in the footer, like other timestamps across the client, adjusts to the user's locale
  • Mentions will only render correctly in the description and field values.
  • Mentions in embeds will not ping users
  • Embeds allow markdown. Field values and description support markdown links.

However, there are some limitations to embeds

  • Titles are limited to 256 characters
  • Descriptions are limited to 4096 characters
  • Each embed can have up to 25 fields
  • A field's name is limited to 256 characters and its value to 1024 characters
  • The footer is limited to 2048 characters
  • The author name is limited to 256 characters
  • Up to 10 embeds can be included in a single message
  • The total length (of the raw json) of all embeds in a message cannot exceed 6000 characters

And the biggest thing to remember: Embeds are rendered client-side and as such, may look different screen-to-screen depending on screen size.

It's always a good idea to plan out and test how your embeds look on desktop and mobile screens.

Что такое эмбеды в дискорде

  • Open with Desktop
  • View raw
  • Copy raw contents Copy raw contents

Copy raw contents

Copy raw contents

Using Embeds in messages

Embeds might look nice but they can be disabled through permissions and user preferences, and will not look the same on mobile — especially complex ones. It’s strongly recommended not to use them unless you have a text-only fallback. Yes they’re nice, but, don’t use them if you don’t need to!

Here are a few rules for embeds:

  • Every field is optional
  • At least one field must be present
  • No field can be empty, null, or undefined.

Those aren’t just guidelines, they are rules, and breaking those rules means your embed will not send — it will return Bad Request .

There are 2 ways to do embeds. The cleanest way is by using the MessageEmbed builder and the second is writing the object itself, we’ll cover the MessageEmbed builder first.

The same rules apply for MessageEmbed as they do for object based ones. In fact, the builder is just a shortcut to get the same object and offers no more, no less functionality.

Which produces the following:

The example embed

Now doesn’t that code look clean and amazing? Well let’s look at the object version.

As you can see it’s bit of a chonker in comparison, but they both output the same embed so there’s no real reason to show it off, congratulations you know how to use embeds in normal messages now!

Not that it’s any different if you’re using a webhook, or an interaction response.

# Embeds

If you have been around on Discord for a bit, chances are you have seen these special messages, often sent by bots. They can have a colored border, embedded images, text fields, and other fancy properties.

In the following section, we will explain how to compose an embed, send it, and what you need to be aware of while doing so.

# Embed preview

Here is an example of how an embed may look. We will go over embed construction in the next part of this guide.

Some name

Some footer text here • 01/01/2018

# Using the embed constructor

discord.js features the EmbedBuilder

open in new window utility class for easy construction and manipulation of embeds.

You don't need to include all the elements showcased above. If you want a simpler embed, leave some out.

The .setColor() method accepts a ColorResolvable

open in new window , e.g. an integer, HEX color string, an array of RGB values or specific color strings.

To add a blank field to the embed, you can use .addFields() .

The above example chains the manipulating methods to the newly created EmbedBuilder object. If you want to modify the embed based on conditions, you will need to reference it as the constant exampleEmbed (for our example).

# Using an embed object

You don't need to include all the elements showcased above. If you want a simpler embed, leave some out.

If you want to modify the embed object based on conditions, you will need to reference it directly (as exampleEmbed for our example). You can then (re)assign the property values as you would with any other object.

# Attaching images

You can upload images with your embedded message and use them as source for embed fields that support image URLs by constructing a AttachmentBuilder

open in new window from them to send as message option alongside the embed. The attachment parameter takes a BufferResolvable or Stream including the URL to an external image.

You can then reference and use the images inside the embed itself with attachment://fileName.extension .

If you plan to attach the same image repeatedly, consider hosting it online and providing the URL in the respective embed field instead. This also makes your bot respond faster since it doesn't need to upload the image with every response depending on it.

# Using the EmbedBuilder

# Using an embed object

If the images don't display inside the embed but outside of it, double-check your syntax to make sure it's as shown above.

# Resending and editing

We will now explain how to edit embedded message content and resend a received embed.

# Resending a received embed

To forward a received embed you retrieve it from the messages embed array ( message.embeds ) and pass it to the EmbedBuilder, then it can be edited before sending it again.

We create a new Embed from EmbedBuilder here since embeds are immutable and their values cannot be changed directly.

# Editing the embedded message content

To edit the content of an embed you need to pass a new EmbedBuilder structure or embed object to the messages .edit() method.

If you want to build the new embed data on a previously sent embed template, make sure to read the caveats in the previous section.

# Notes

  • To display fields side-by-side, you need at least two consecutive fields set to inline
  • The timestamp will automatically adjust the timezone depending on the user's device
  • Mentions of any kind in embeds will only render correctly within embed descriptions and field values
  • Mentions in embeds will not trigger a notification
  • Embeds allow masked links (e.g. [Guide](https://discordjs.guide/ 'optional hovertext') ), but only in description and field values

# Embed limits

There are a few limits to be aware of while planning your embeds due to the API's limitations. Here is a quick reference you can come back to:

Embed сообщения в дискорде: что это такое, как написать?

Реальная жизнь для многих практически утратила красоту – все интересы планомерно переходят в виртуальное пространство. В онлайн режиме пользователи находят единомышленников, объединяются в группы и делятся впечатлениями. Тематическое общение возможно благодаря функционалу приложения, доступным настройкам и инструментам. Это новый формат, который позволяет еще проще коммуницировать и находить общие темы.

С помощью мессенджера Дискорд создаются embed сообщения, а также есть возможность задействовать серверы, на их базе накалы, где уже в дальнейшем для общения на какую-то определенную тему добавляют участников. Это относительно новая функция, поэтому многие еще не все в курсе, что это и как правильно писать такие сообщения.

Что это

Дискорд – многофункциональная программа, которая позволяет использовать данные сторонних сайтов и публиковать интересную информацию на заданном сервере. Интерфейс помогает встраивать определенный контент со сторонней страницы, что в результате дает уникальный элемент за счет полнофункциональных инструментов.

Как написать

Способ для ботов – самый доступный вариант, чтобы создавать embed сообщения. В нем сочетается простота и эффективность – в арсенале достаточно настроек, чтобы решить такого рода задачи. В основе процедуры лежит процесс генерирования эмбеда, который включает следующие шаги:

  1. Войти в мессенджер и выбрать подходящий вариант для набора сообщений.
  2. В строке ввода текста, пользователи выбирают символ, который представлен как квадрат с папками в горизонтальном положении.
  3. В меню выбрать соответствующие данные о плагине. Следует определить цветовое решение, придумать подходящее название. Для создания правильного образа потребуется выбрать картинку.
  4. Если никаких изменений не требуется просто сохранить результат и нажать «Отправить». На этом этапе embed готов для использования.

Среди последних изменений представленных разработчиками заимствование данных стороннего сайта, что удобно использовать для размещения дополнительной информации непосредственно на сервере пользователя и пополнять сообщества новыми темами.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *