Embeds send support
maybe ... + fix message edit
This commit is contained in:
		@@ -319,7 +319,6 @@ message.channel.send({ content: `Hello world`, embeds: [w] }) // Patched :)
 | 
			
		||||
- Video with Embed working
 | 
			
		||||
- Description limit 350 characters
 | 
			
		||||
- If you use hidden mode you must make sure your custom content is less than 1000 characters without nitro (because hidden mode uses 1000 characters + URL)
 | 
			
		||||
- <strong>PLEASE DON'T CREATE TOO MUCH EMBED WITH SHORTEN OPTION BECAUSE IT CAN OVERLOAD MY API (I USE API HOST BY HEROKU)</strong>
 | 
			
		||||
 | 
			
		||||
</details>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -124,12 +124,16 @@ class MessageManager extends CachedManager {
 | 
			
		||||
    const messageId = this.resolveId(message);
 | 
			
		||||
    if (!messageId) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
 | 
			
		||||
 | 
			
		||||
    const { data, files } = await (options instanceof MessagePayload
 | 
			
		||||
      ? options
 | 
			
		||||
      : MessagePayload.create(message instanceof Message ? message : this, options)
 | 
			
		||||
    )
 | 
			
		||||
      .resolveData()
 | 
			
		||||
      .resolveFiles();
 | 
			
		||||
    let messagePayload;
 | 
			
		||||
    if (options instanceof MessagePayload) {
 | 
			
		||||
      messagePayload = await options.resolveData();
 | 
			
		||||
    } else {
 | 
			
		||||
      messagePayload = await MessagePayload.create(
 | 
			
		||||
				message instanceof Message ? message : this,
 | 
			
		||||
				options,
 | 
			
		||||
			).resolveData();
 | 
			
		||||
    }
 | 
			
		||||
    const { data, files } = await messagePayload.resolveFiles();
 | 
			
		||||
    const d = await this.client.api.channels[this.channel.id].messages[messageId].patch({ data, files });
 | 
			
		||||
 | 
			
		||||
    const existing = this.cache.get(messageId);
 | 
			
		||||
@@ -220,15 +224,15 @@ class MessageManager extends CachedManager {
 | 
			
		||||
    // const data = await this.client.api.channels[this.channel.id].messages[messageId].get(); // Discord Block
 | 
			
		||||
    // https://canary.discord.com/api/v9/guilds/809133733591384155/messages/search?channel_id=840225732902518825&max_id=957254525360697375&min_id=957254525360697373
 | 
			
		||||
    const data = (
 | 
			
		||||
			await this.client.api.guilds[this.channel.guild.id].messages.search.get({
 | 
			
		||||
				query: {
 | 
			
		||||
					channel_id: this.channel.id,
 | 
			
		||||
					max_id: new BigNumber.BigNumber(messageId).plus(1).toString(),
 | 
			
		||||
					min_id: new BigNumber.BigNumber(messageId).minus(1).toString(),
 | 
			
		||||
				},
 | 
			
		||||
			})
 | 
			
		||||
		).messages[0]
 | 
			
		||||
    if (data) return this._add(data[0],	cache);
 | 
			
		||||
      await this.client.api.guilds[this.channel.guild.id].messages.search.get({
 | 
			
		||||
        query: {
 | 
			
		||||
          channel_id: this.channel.id,
 | 
			
		||||
          max_id: new BigNumber.BigNumber(messageId).plus(1).toString(),
 | 
			
		||||
          min_id: new BigNumber.BigNumber(messageId).minus(1).toString(),
 | 
			
		||||
        },
 | 
			
		||||
      })
 | 
			
		||||
    ).messages[0]
 | 
			
		||||
    if (data) return this._add(data[0], cache);
 | 
			
		||||
    else throw new Error('MESSAGE_ID_NOT_FOUND');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -195,19 +195,21 @@ class MessagePayload {
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      const webembeds = this.options.embeds.filter(
 | 
			
		||||
				(e) => !(e instanceof MessageEmbed),
 | 
			
		||||
			);
 | 
			
		||||
        (e) => !(e instanceof MessageEmbed),
 | 
			
		||||
      );
 | 
			
		||||
      this.options.embeds = this.options.embeds.filter(e => e instanceof MessageEmbed);
 | 
			
		||||
 | 
			
		||||
      if (webembeds.length > 0) {
 | 
			
		||||
        // add hidden embed link
 | 
			
		||||
        content += `\n${WebEmbed.hiddenEmbed} \n`;
 | 
			
		||||
        if (webembeds.length > 1) {
 | 
			
		||||
          console.warn('Multiple webembeds are not supported, only the first one will be sent');
 | 
			
		||||
          console.warn('Multiple webembeds are not supported, this will be ignored.');
 | 
			
		||||
        }
 | 
			
		||||
        // const embed = webembeds[0];
 | 
			
		||||
        for (const webE of webembeds) {
 | 
			
		||||
          const data = await webE.toMessage();
 | 
			
		||||
          content += `\n${data}`;
 | 
			
		||||
        }
 | 
			
		||||
        const embed = webembeds[0];
 | 
			
		||||
        const data = await embed.toMessage();
 | 
			
		||||
        content += `\n${data}`;
 | 
			
		||||
      }
 | 
			
		||||
      // Check content
 | 
			
		||||
      if (content.length > 2000) {
 | 
			
		||||
@@ -217,7 +219,7 @@ class MessagePayload {
 | 
			
		||||
        throw new RangeError('MESSAGE_EMBED_LINK_LENGTH');
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    this.data = {
 | 
			
		||||
      content,
 | 
			
		||||
      tts,
 | 
			
		||||
 
 | 
			
		||||
@@ -301,7 +301,7 @@ class WebEmbed {
 | 
			
		||||
// Credit: https://www.npmjs.com/package/node-url-shortener + google :))
 | 
			
		||||
const getShorten = async (url) => {
 | 
			
		||||
    const APIurl = [
 | 
			
		||||
        'https://is.gd/create.php?format=simple&url=',
 | 
			
		||||
        // 'https://is.gd/create.php?format=simple&url=', :(
 | 
			
		||||
        'https://tinyurl.com/api-create.php?url=',
 | 
			
		||||
        // 'https://cdpt.in/shorten?url=', Redirects 5s :(
 | 
			
		||||
    ];
 | 
			
		||||
 
 | 
			
		||||
@@ -316,11 +316,15 @@ class Webhook {
 | 
			
		||||
    if (!this.token) throw new Error('WEBHOOK_TOKEN_UNAVAILABLE');
 | 
			
		||||
 | 
			
		||||
    let messagePayload;
 | 
			
		||||
 | 
			
		||||
    if (options instanceof MessagePayload) messagePayload = options;
 | 
			
		||||
    else messagePayload = MessagePayload.create(this, options);
 | 
			
		||||
 | 
			
		||||
    const { data, files } = await messagePayload.resolveData().resolveFiles();
 | 
			
		||||
		if (options instanceof MessagePayload) {
 | 
			
		||||
			messagePayload = await options.resolveData();
 | 
			
		||||
		} else {
 | 
			
		||||
			messagePayload = await MessagePayload.create(
 | 
			
		||||
				message instanceof Message ? message : this,
 | 
			
		||||
				options,
 | 
			
		||||
			).resolveData();
 | 
			
		||||
		}
 | 
			
		||||
		const { data, files } = await messagePayload.resolveFiles();
 | 
			
		||||
 | 
			
		||||
    const d = await this.client.api
 | 
			
		||||
      .webhooks(this.id, this.token)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user