mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23: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
|
||||
*/
|
||||
|
||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -3256,7 +3256,7 @@ declare module 'discord.js' {
|
||||
interface MessageEditOptions {
|
||||
attachments?: MessageAttachment[];
|
||||
content?: string | null;
|
||||
embed?: MessageEmbed | MessageEmbedOptions | null;
|
||||
embeds?: (MessageEmbed | MessageEmbedOptions)[] | null;
|
||||
code?: string | boolean;
|
||||
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
||||
flags?: BitFieldResolvable<MessageFlagsString, number>;
|
||||
@@ -3352,7 +3352,7 @@ declare module 'discord.js' {
|
||||
tts?: boolean;
|
||||
nonce?: string | number;
|
||||
content?: string;
|
||||
embed?: MessageEmbed | MessageEmbedOptions;
|
||||
embeds?: (MessageEmbed | MessageEmbedOptions)[];
|
||||
components?: MessageActionRow[] | MessageActionRowOptions[] | MessageActionRowComponentResolvable[][];
|
||||
allowedMentions?: MessageMentionOptions;
|
||||
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
||||
@@ -3754,10 +3754,9 @@ declare module 'discord.js' {
|
||||
'content' | 'embeds' | 'files' | 'allowedMentions' | 'components'
|
||||
>;
|
||||
|
||||
interface WebhookMessageOptions extends Omit<MessageOptions, 'embed' | 'reply'> {
|
||||
interface WebhookMessageOptions extends Omit<MessageOptions, 'reply'> {
|
||||
username?: string;
|
||||
avatarURL?: string;
|
||||
embeds?: (MessageEmbed | unknown)[];
|
||||
}
|
||||
|
||||
type WebhookTypes = 'Incoming' | 'Channel Follower';
|
||||
|
||||
@@ -34,13 +34,13 @@ declare const assertIsMessageArray: (m: Promise<Message[]>) => void;
|
||||
client.on('message', ({ channel }) => {
|
||||
assertIsMessage(channel.send('string'));
|
||||
assertIsMessage(channel.send({}));
|
||||
assertIsMessage(channel.send({ embed: {} }));
|
||||
assertIsMessage(channel.send({ embeds: [] }));
|
||||
|
||||
const attachment = new MessageAttachment('file.png');
|
||||
const embed = new MessageEmbed();
|
||||
assertIsMessage(channel.send({ files: [attachment] }));
|
||||
assertIsMessage(channel.send({ embed }));
|
||||
assertIsMessage(channel.send({ embed, files: [attachment] }));
|
||||
assertIsMessage(channel.send({ embeds: [embed] }));
|
||||
assertIsMessage(channel.send({ embeds: [embed], files: [attachment] }));
|
||||
|
||||
assertIsMessageArray(channel.send({ split: true }));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user