mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +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;
|
if (this.data) return this;
|
||||||
const isInteraction = this.isInteraction;
|
const isInteraction = this.isInteraction;
|
||||||
const isWebhook = this.isWebhook;
|
const isWebhook = this.isWebhook;
|
||||||
const isWebhookLike = isInteraction || isWebhook;
|
|
||||||
|
|
||||||
const content = this.makeContent();
|
const content = this.makeContent();
|
||||||
const tts = Boolean(this.options.tts);
|
const tts = Boolean(this.options.tts);
|
||||||
@@ -144,14 +143,9 @@ class APIMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const embedLikes = [];
|
const embedLikes = [];
|
||||||
if (isWebhookLike) {
|
if (this.options.embeds) {
|
||||||
if (this.options.embeds) {
|
embedLikes.push(...this.options.embeds);
|
||||||
embedLikes.push(...this.options.embeds);
|
|
||||||
}
|
|
||||||
} else if (this.options.embed) {
|
|
||||||
embedLikes.push(this.options.embed);
|
|
||||||
}
|
}
|
||||||
const embeds = embedLikes.map(e => new MessageEmbed(e).toJSON());
|
|
||||||
|
|
||||||
const components = this.options.components?.map(c =>
|
const components = this.options.components?.map(c =>
|
||||||
BaseMessageComponent.create(
|
BaseMessageComponent.create(
|
||||||
@@ -202,8 +196,7 @@ class APIMessage {
|
|||||||
content,
|
content,
|
||||||
tts,
|
tts,
|
||||||
nonce,
|
nonce,
|
||||||
embed: !isWebhookLike ? (this.options.embed === null ? null : embeds[0]) : undefined,
|
embeds: this.options.embeds?.map(embed => new MessageEmbed(embed).toJSON()),
|
||||||
embeds: isWebhookLike ? embeds : undefined,
|
|
||||||
components,
|
components,
|
||||||
username,
|
username,
|
||||||
avatar_url: avatarURL,
|
avatar_url: avatarURL,
|
||||||
@@ -223,6 +216,22 @@ class APIMessage {
|
|||||||
async resolveFiles() {
|
async resolveFiles() {
|
||||||
if (this.files) return this;
|
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)) ?? []);
|
this.files = await Promise.all(this.options.files?.map(file => this.constructor.resolveFile(file)) ?? []);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class TextBasedChannel {
|
|||||||
/**
|
/**
|
||||||
* Options provided when sending or editing a message.
|
* Options provided when sending or editing a message.
|
||||||
* @typedef {BaseMessageOptions} MessageOptions
|
* @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)
|
* (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details)
|
||||||
* @property {ReplyOptions} [reply] The options for replying to a message
|
* @property {ReplyOptions} [reply] The options for replying to a message
|
||||||
*/
|
*/
|
||||||
|
|||||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -3256,7 +3256,7 @@ declare module 'discord.js' {
|
|||||||
interface MessageEditOptions {
|
interface MessageEditOptions {
|
||||||
attachments?: MessageAttachment[];
|
attachments?: MessageAttachment[];
|
||||||
content?: string | null;
|
content?: string | null;
|
||||||
embed?: MessageEmbed | MessageEmbedOptions | null;
|
embeds?: (MessageEmbed | MessageEmbedOptions)[] | null;
|
||||||
code?: string | boolean;
|
code?: string | boolean;
|
||||||
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
||||||
flags?: BitFieldResolvable<MessageFlagsString, number>;
|
flags?: BitFieldResolvable<MessageFlagsString, number>;
|
||||||
@@ -3352,7 +3352,7 @@ declare module 'discord.js' {
|
|||||||
tts?: boolean;
|
tts?: boolean;
|
||||||
nonce?: string | number;
|
nonce?: string | number;
|
||||||
content?: string;
|
content?: string;
|
||||||
embed?: MessageEmbed | MessageEmbedOptions;
|
embeds?: (MessageEmbed | MessageEmbedOptions)[];
|
||||||
components?: MessageActionRow[] | MessageActionRowOptions[] | MessageActionRowComponentResolvable[][];
|
components?: MessageActionRow[] | MessageActionRowOptions[] | MessageActionRowComponentResolvable[][];
|
||||||
allowedMentions?: MessageMentionOptions;
|
allowedMentions?: MessageMentionOptions;
|
||||||
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
||||||
@@ -3754,10 +3754,9 @@ declare module 'discord.js' {
|
|||||||
'content' | 'embeds' | 'files' | 'allowedMentions' | 'components'
|
'content' | 'embeds' | 'files' | 'allowedMentions' | 'components'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
interface WebhookMessageOptions extends Omit<MessageOptions, 'embed' | 'reply'> {
|
interface WebhookMessageOptions extends Omit<MessageOptions, 'reply'> {
|
||||||
username?: string;
|
username?: string;
|
||||||
avatarURL?: string;
|
avatarURL?: string;
|
||||||
embeds?: (MessageEmbed | unknown)[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebhookTypes = 'Incoming' | 'Channel Follower';
|
type WebhookTypes = 'Incoming' | 'Channel Follower';
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ declare const assertIsMessageArray: (m: Promise<Message[]>) => void;
|
|||||||
client.on('message', ({ channel }) => {
|
client.on('message', ({ channel }) => {
|
||||||
assertIsMessage(channel.send('string'));
|
assertIsMessage(channel.send('string'));
|
||||||
assertIsMessage(channel.send({}));
|
assertIsMessage(channel.send({}));
|
||||||
assertIsMessage(channel.send({ embed: {} }));
|
assertIsMessage(channel.send({ embeds: [] }));
|
||||||
|
|
||||||
const attachment = new MessageAttachment('file.png');
|
const attachment = new MessageAttachment('file.png');
|
||||||
const embed = new MessageEmbed();
|
const embed = new MessageEmbed();
|
||||||
assertIsMessage(channel.send({ files: [attachment] }));
|
assertIsMessage(channel.send({ files: [attachment] }));
|
||||||
assertIsMessage(channel.send({ embed }));
|
assertIsMessage(channel.send({ embeds: [embed] }));
|
||||||
assertIsMessage(channel.send({ embed, files: [attachment] }));
|
assertIsMessage(channel.send({ embeds: [embed], files: [attachment] }));
|
||||||
|
|
||||||
assertIsMessageArray(channel.send({ split: true }));
|
assertIsMessageArray(channel.send({ split: true }));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user