Merge pull request #14 from lazuee/main

revert embeds, add webembed as optional
This commit is contained in:
March 7th 2022-04-01 19:53:08 +07:00 committed by GitHub
commit d233d0e83e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -3,6 +3,7 @@
const { Buffer } = require('node:buffer');
const BaseMessageComponent = require('./BaseMessageComponent');
const MessageEmbed = require('./MessageEmbed');
const WebEmbed = require('./WebEmbed');
const { RangeError } = require('../errors');
const DataResolver = require('../util/DataResolver');
const MessageFlags = require('../util/MessageFlags');
@ -188,6 +189,21 @@ class MessagePayload {
this.options.attachments = attachments;
}
if (this.options.embeds) {
if (!Array.isArray(this.options.embeds)) {
this.options.embeds = [this.options.embeds];
}
let webembeds = this.options.embeds.filter(e => e instanceof WebEmbed);
this.options.embeds = this.options.embeds.filter(e => !(e instanceof WebEmbed));
while (webembeds.length) {
const embed = webembeds.shift();
const data = await embed.toMessage();
content +=`\n${data}`
}
}
this.data = {
content,
tts,

View File

@ -58,7 +58,7 @@ class TextBasedChannel {
* @property {boolean} [tts=false] Whether or not the message should be spoken aloud
* @property {string} [nonce=''] The nonce for the message
* @property {string} [content=''] The content for the message
* @property {MessageEmbed[]|APIEmbed[]} [embeds] The embeds for the message
* @property {WebEmbed[]|MessageEmbed[]|APIEmbed[]} [embeds] The embeds for the message
* (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details)
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
* (see [here](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for more details)

2
typings/index.d.ts vendored
View File

@ -5247,7 +5247,7 @@ export interface MessageOptions {
tts?: boolean;
nonce?: string | number;
content?: string | null;
embeds?: (MessageEmbed | MessageEmbedOptions | APIEmbed)[];
embeds?: (WebEmbed | MessageEmbed | MessageEmbedOptions | APIEmbed)[];
components?: (MessageActionRow | (Required<BaseMessageComponentOptions> & MessageActionRowOptions))[];
allowedMentions?: MessageMentionOptions;
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];