How to delete a messageEmbed after 9 seconds. [BOT Discord]

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

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

# Embed preview

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

10/07/2019
Some title
Some description here
Regular field title

Some value here

Inline field title

Some value here

Inline field title

Some value here

Inline field title

Some value here

Some footer text here

01/01/2018

# Using the RichEmbed constructor

WARNING

On the master branch, the receiving and outgoing embed classes have been unified; you will need to use Discord.MessageEmbed()
as constructor instead.

// at the top of your file
 const
 Discord =
 require
(
'discord.js'
)
;
  // inside a command, event listener, etc.
 const
 exampleEmbed =
 new
 Discord.
RichEmbed
(
)
 .
setColor
(
'#0099ff'
)
 .
setTitle
(
'Some title'
)
 .
setURL
(
'https://discord.js.org/'
)
 .
setAuthor
(
'Some name'
,
 'https://totalmessengers.ru/wp-content/uploads/2020/01/pp_image_33344_54s85cymstwSTFkRM.jpg'
,
 'https://discord.js.org'
)
 .
setDescription
(
'Some description here'
)
 .
setThumbnail
(
'https://totalmessengers.ru/wp-content/uploads/2020/01/pp_image_33344_54s85cymstwSTFkRM.jpg'
)
 .
addField
(
'Regular field title'
,
 'Some value here'
)
 .
addBlankField
(
)
 .
addField
(
'Inline field title'
,
 'Some value here'
,
 true
)
 .
addField
(
'Inline field title'
,
 'Some value here'
,
 true
)
 .
addField
(
'Inline field title'
,
 'Some value here'
,
 true
)
 .
setImage
(
'https://totalmessengers.ru/wp-content/uploads/2020/01/pp_image_33344_54s85cymstwSTFkRM.jpg'
)
 .
setTimestamp
(
)
 .
setFooter
(
'Some footer text here'
,
 'https://totalmessengers.ru/wp-content/uploads/2020/01/pp_image_33344_54s85cymstwSTFkRM.jpg'
)
;
  channel.
send
(
exampleEmbed)
;
 

TIP

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

The .setColor()
method accepts an integer, HEX color string, an array of RGB values or specific color strings. You can find a list of them at .

.addBlankField()
is a convenience method for .addField('u200b', 'u200b')
to add a spacer to the embed. This can also be used inline by passing true
as the first parameter.

The above example chains the manipulating methods to the newly created RichEmbed object. This is possible because the return value of each manipulating method is the RichEmbed instance itself. If you want to modify the embed based on conditions you will need to reference it directly (as exampleEmbed
for our example).

const
 exampleEmbed =
 new
 Discord.
RichEmbed
(
)
.
setTitle
(
'Some title'
)
;
  if
 (
message.
author.
bot)
 {
 exampleEmbed.
setColor
(
'#7289da'
)
;
 }
 

# Local images

To use local images inside your embed, you need to upload them alongside the embed with the .attachFiles()
method. You can either provide the file path , BufferResolvable, or Attachment objects inside an array.

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

const
 exampleEmbed =
 new
 Discord.
RichEmbed
(
)
 .
setTitle
(
'Some title'
)
 .
attachFiles
(
[
'../assets/discordjs.png'
]
)
 .
setImage
(
'attachment://discordjs.png'
)
;
  channel.
send
(
exampleEmbed)
;
 

WARNING

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

# Using an embed object

const
 exampleEmbed =
 {
 color:
 0x0099ff
,
 title:
 'Some title'
,
 url:
 'https://discord.js.org'
,
 author:
 {
 name:
 'Some name'
,
 icon_url:
 'https://totalmessengers.ru/wp-content/uploads/2020/01/pp_image_33344_54s85cymstwSTFkRM.jpg'
,
 url:
 'https://discord.js.org'
,
 }
,
 description:
 'Some description here'
,
 thumbnail:
 {
 url:
 'https://totalmessengers.ru/wp-content/uploads/2020/01/pp_image_33344_54s85cymstwSTFkRM.jpg'
,
 }
,
 fields:
 [
 {
 name:
 'Regular field title'
,
 value:
 'Some value here'
,
 }
,
 {
 name:
 'u200b'
,
 value:
 'u200b'
,
 }
,
 {
 name:
 'Inline field title'
,
 value:
 'Some value here'
,
 inline:
 true
,
 }
,
 {
 name:
 'Inline field title'
,
 value:
 'Some value here'
,
 inline:
 true
,
 }
,
 {
 name:
 'Inline field title'
,
 value:
 'Some value here'
,
 inline:
 true
,
 }
,
 ]
,
 image:
 {
 url:
 'https://totalmessengers.ru/wp-content/uploads/2020/01/pp_image_33344_54s85cymstwSTFkRM.jpg'
,
 }
,
 timestamp:
 new
 Date
(
)
,
 footer:
 {
 text:
 'Some footer text here'
,
 icon_url:
 'https://totalmessengers.ru/wp-content/uploads/2020/01/pp_image_33344_54s85cymstwSTFkRM.jpg'
,
 }
,
 }
;
  channel.
send
(
{
 embed:
 exampleEmbed }
)
;
 

TIP

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

WARNING

The color
field has to be an integer for embed objects! If you have a hex color string (e.g. '#7289da'
) you can replace the #
with 0x
to use it as a number: 0x7289da
.

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.

const
 exampleEmbed =
 {
 title:
 'Some title'
 }
;
  if
 (
message.
author.
bot)
 {
 exampleEmbed.
color =
 0x7289da
;
 }
 

# Local images

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

const
 file =
 new
 Discord.
Attachment
(
'../assets/discordjs.png'
)
;
  const
 exampleEmbed =
 {
 title:
 'Some title'
,
 image:
 {
 url:
 'attachment://discordjs.png'
,
 }
,
 }
;
  channel.
send
(
{
 files:
 [
file]
,
 embed:
 exampleEmbed }
)
;
 

WARNING

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

# Resending embeds

At some point in your bot development, you might want to get an embed from a message that you’re receiving, edit it, and send it again.

To achieve this, you retrieve the embed from the messages embed array (message.embeds
) and pass it to the RichEmbed constructor. The constructed RichEmbed can then be edited before sending it again.

WARNING

const
 receivedEmbed =
 message.
embeds[
0
]
;
 const
 exampleEmbed =
 new
 Discord.
RichEmbed
(
receivedEmbed)
.
setTitle
(
'New title'
)
;
  channel.
send
(
exampleEmbed)
;
 

# Notes

  • To display fields side-by-side, you need at least two consecutive fields set to inline
  • By default, up to 3 fields will display inline. If a thumbnail is set, this will change to 2
  • The timestamp will automatically adjust the timezone depending on the user’s device
  • Mentions of any kind will only render correctly in field values and descriptions
  • 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 limitations set by the API. Here is a quick reference you can come back to:

  • Embed titles are limited to 256 characters
  • Embed descriptions are limited to 2048 characters
  • There can be up to 25 fields
  • A field’s name is limited to 256 characters and its value to 1024 characters
  • The footer text is limited to 2048 characters
  • The author name is limited to 256 characters
  • In addition, the sum of all characters in an embed structure must not exceed 6000 characters
  • A bot can have 1 embed per message
  • A webhook can have 10 embeds per message
Asked
2 months ago
Active
2 months ago
Viewed
47 times

With my Discord bot, I would like to delete a message the client sent after 9 seconds. I have already tried with message.delete([1000])
, but this deletes the message sent by the user
.

This is my current attempt:

message.channel.send({embed: {     color: 15488557,     title: '❌ Problème dans la commande.', }});  message.delete([10000]) 
|
improve this question

2 Answers 2

active oldest votes

Your problem is message.delete()
this means: delete user
message not client(bot)
message. You need to do .then(m => m.delete())
, good luck!

|
improve this answer
1

TextBasedChannel.send()
returns a Promise resolving with the Message sent. That means that in your case, you can attach a then()
method to use the returned value.

|
improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.

Эмбед
— специальное сообщение, которые могут оставлять только боты, однако и обычные пользователи дискорда могут также присылать эмбеды, для этого нужен модификатор Discord (BBD, ED или селфбот, тут стоить напомнить, что за это ваш аккаунт могут заблокировать). Эмбед выглядит как сообщение, но с цветной линией слева сбоку, все эмбеды разные по «начинке», например по иконке, баннеру, заголовкам, есть ещё множество мелочей, которые довольно долго озвучивать.

Как прислать эмбед?
Править

Способ для ботов
Править

JavaScript
Править

Недоделанный раздел!

Python
Править

Недоделанный раздел!

Discord Bot Maker
Править

1. Для начала нам нужно создать команду, у нас это будет тест-эмбеда-для-вики

2. Потом, нажмите «Create» и нажмите на «Send Message», потом выберите категорию «Messaging» и там выберите «Create Embed Messagse»

2 шаг

2.1. Вписываем заголовок эмбеда, URL, Автора, цвет, изображение. Потом пишем в «Variable Name», например, «varembed» и сохраняем.

3. Нажимаем опять кнопку «Create», выбираем ту же самую категорию и выбираем уже «Set Embed Description».

3.1. Вписываем «Variable Name», который мы написали в прошлом событии, у нас это был «varembed», вписываем.

3.2. А дальше просто пишем, что у нас будет в эмбеде, у нас это «embed test».

4. Дальше создаём ещё одно событие в команде, выбираем также «Messaging», но функцию уже выбираем «Send Embed Message».

4.1. Вписываем «Variable Name», в нашем случае это «varembed». Потом можем выбрать куда сообщение придёт и готово!

Эмбед с помощью Discord Bot Maker был создан, осталось запустить вашего бота и продемонстрировать эту команду.

BetterDiscord
Править

В интернете можно найти плагин, который сможет отсылать эмбеды, в данном случаи опишется плагин «Safe Embed Generator».

1. Скачиваем плагин по ссылке *клик*.

1.1 Перекидываем в папку %appdata%/BetterDiscord/plugins

1.2 Подключаем его в настройках пользователя во вкладке «Plugins».

Создаём (Генерируем) эмбед
Править

1. Нажимаем на кнопку в поле ввода сообщения.

2. Когда вы видите это, не бойтесь. Заполняйте всё как вам надо, сбоку появится превью эмбеда. Как и в Discord Bot Maker тут можно выбрать цвет, картинку, автора, заголовок.

3. Когда вы всё заполнили, можете нажимать «Send», и у вас отправится эмбед!

Материалы сообщества доступны в соответствии с условиями лицензии CC-BY-SA , если не указано иное.
Рейтинг автора
5
Подборку подготовил
Андрей Ульянов
Наш эксперт
Написано статей
168
Ссылка на основную публикацию
Похожие публикации