mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
feat(*): document and support embeds field in message create endpoint (#5792)
Co-authored-by: ckohen <chaikohen@gmail.com> Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com>
This commit is contained in:
@@ -129,7 +129,6 @@ class APIMessage {
|
||||
if (this.data) return this;
|
||||
const isInteraction = this.isInteraction;
|
||||
const isWebhook = this.isWebhook;
|
||||
const isWebhookLike = isInteraction || isWebhook;
|
||||
|
||||
const content = this.makeContent();
|
||||
const tts = Boolean(this.options.tts);
|
||||
@@ -144,14 +143,9 @@ class APIMessage {
|
||||
}
|
||||
|
||||
const embedLikes = [];
|
||||
if (isWebhookLike) {
|
||||
if (this.options.embeds) {
|
||||
embedLikes.push(...this.options.embeds);
|
||||
}
|
||||
} else if (this.options.embed) {
|
||||
embedLikes.push(this.options.embed);
|
||||
if (this.options.embeds) {
|
||||
embedLikes.push(...this.options.embeds);
|
||||
}
|
||||
const embeds = embedLikes.map(e => new MessageEmbed(e).toJSON());
|
||||
|
||||
const components = this.options.components?.map(c =>
|
||||
BaseMessageComponent.create(
|
||||
@@ -202,8 +196,7 @@ class APIMessage {
|
||||
content,
|
||||
tts,
|
||||
nonce,
|
||||
embed: !isWebhookLike ? (this.options.embed === null ? null : embeds[0]) : undefined,
|
||||
embeds: isWebhookLike ? embeds : undefined,
|
||||
embeds: this.options.embeds?.map(embed => new MessageEmbed(embed).toJSON()),
|
||||
components,
|
||||
username,
|
||||
avatar_url: avatarURL,
|
||||
@@ -223,6 +216,22 @@ class APIMessage {
|
||||
async resolveFiles() {
|
||||
if (this.files) return this;
|
||||
|
||||
const embedLikes = [];
|
||||
|
||||
if (this.options.embeds) {
|
||||
embedLikes.push(...this.options.embeds);
|
||||
}
|
||||
|
||||
const fileLikes = [];
|
||||
if (this.options.files) {
|
||||
fileLikes.push(...this.options.files);
|
||||
}
|
||||
for (const embed of embedLikes) {
|
||||
if (embed.files) {
|
||||
fileLikes.push(...embed.files);
|
||||
}
|
||||
}
|
||||
|
||||
this.files = await Promise.all(this.options.files?.map(file => this.constructor.resolveFile(file)) ?? []);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class TextBasedChannel {
|
||||
/**
|
||||
* Options provided when sending or editing a message.
|
||||
* @typedef {BaseMessageOptions} MessageOptions
|
||||
* @property {MessageEmbed|Object} [embed] An embed for the message
|
||||
* @property {MessageEmbed[]|Object[]} [embeds] The embeds for the message
|
||||
* (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details)
|
||||
* @property {ReplyOptions} [reply] The options for replying to a message
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user