From 2d3e6ec271da6839d7b8cb74043aa63ef26d5a87 Mon Sep 17 00:00:00 2001 From: John Marlo Date: Fri, 1 Apr 2022 15:54:01 +0800 Subject: [PATCH] Remove default embeds option.. --- src/structures/MessagePayload.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/structures/MessagePayload.js b/src/structures/MessagePayload.js index 339b8f9..d9346b7 100644 --- a/src/structures/MessagePayload.js +++ b/src/structures/MessagePayload.js @@ -2,7 +2,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,11 +188,29 @@ class MessagePayload { this.options.attachments = attachments; } + if (this.options.embeds) { + //check if embeds is an array + if (!Array.isArray(this.options.embeds)) { + this.options.embeds = [this.options.embeds]; + } + + //check if the embeds is an array of WebEmbed + if (!this.options.embeds.every(e => e instanceof WebEmbed)) { + throw new TypeError('WEB_EMBEDS_TYPE'); + } + + //while loop to make sure all embeds will be added to the content + while (this.options.embeds.length) { + const embed = this.options.embeds.shift(); + const data = await embed.toMessage(true, true); //set to true hidden, shorten... + content +=`\n${data}` + } + } + this.data = { content, tts, nonce, - embeds: this.options.embeds?.map(embed => new MessageEmbed(embed).toJSON()), components, username, avatar_url: avatarURL,