Search code examples
discord.jsembed

Displaying urls with embedded content (djs v12)


I am looking to display a image / gif url in the embed, if it has embedded content it will show it along with the url. Currently, I only figured out how to display if the message was uploaded to discord as a attachment.

Example, the avatar is shown within the embed. This is the same concept I want for images with embedded content.

 const embed = new MessageEmbed()
 
   

      .setDescription(message.content)
      .setColor("#E74C3C")
      .setTimestamp()
      .setImage(message.attachments.array().length == 0 ? null:message.attachments.first().url)
      .setAuthor(
        message.author.tag,
        message.author.displayAvatarURL({ dynamic: true })
      
    );

Solution

  • From what I understand is you are trying to set an image into your embed of an already existing image to the embed that shows while we put our URL.

    You can simply use the MessageEmbed constructor's MessageEmbed#setImage() method along with extracting the image from the link as the URL parameter to the method like so ( for that you need to send it to discord first ) :

    
        const { MessageEmbed } = require("discord.js")
        message.channel.send("https://discord.com/").then( (embeddedmessage) => {
        let image = embeddedmessage.embeds[0].thumbnail.url
        const x = new MessageEmbed()
        x.setTitle("Discord URL's Image")
        x.setImage(image);
        embeddedmessage.edit(x);
        });
        
    

    The message with the URL ( if has an embed ) would have an rich embed object which would justify the image present within it ( here is the example object from the URL we took in our code:

    {
        "title": "Discord | Your Place to Talk and Hang Out",
        "type": "rich",
        "description": "Discord is the easiest way to talk over voice, video, and text. Talk, chat, hang out, and stay close with your friends and communities.",
        "url": "https://discord.com/",
        "timestamp": null,
        "color": null,
        "fields": [],
        "thumbnail": {
            "url": "https://discord.com/assets/652f40427e1f5186ad54836074898279.png",
            "proxyURL": "https://images-ext-2.discordapp.net/external/pL0w57uLXr8vYKityoLlH1CVuGCs0fB5xnrWKO8Fqoo/https/discord.com/assets/652f40427e1f5186ad54836074898279.png",
            "height": 630,
            "width": 1200
        },
        "image": null,
        "author": null,
        "footer": null
    }