Skip to content Skip to sidebar Skip to footer

How To Use Local File As Thumbnail In DiscordJS Embedded Message?

Is it possible to use a local file as a thumbnail for an embedded message with DiscordJs? 'thumbnail': { 'url': '../img/025.png' }, This doesn't seem to work. (node:34721) Unhan

Solution 1:

I've already found an answer. Linking to the proper url of the file wasn't an option for me, because some images were generated.

You can attach an image to the message, and use this attachment as thumbnail. Most basic example:

const embed = {
  "title": "A Title" ,
  "color": 0xF96221,
  "thumbnail": {
    "url": "attachment://image.png"
  },
  "fields": [
    {
      "name": "Field 1:",
      "value": "One",
      "inline": false
    },
    {
      "name": "Field 2:",
      "value": "Two",
      "inline": true,
    },
    {
      "name":"Field 3:",
      "value":"Three",
      "inline": true
    },
  ],
  "footer": {
    "text":"Footer text"
  }
};

Attach the image to the message with:

message.channel.send({
  embed,
  files: [{
    attachment:'img/image.png',
    name:'image.png'
  }]
});

Solution 2:

Other way to do, I hope it helps

const attachment = new Discord.MessageAttachment('fileRoute', 'nameOfYourPicture');
const embed = new Discord.MessageEmbed()
  .setTitle('Title')
  .setColor('#8fda81')
  .addField('Message Send', messageToSend)
  .attachFiles(attachment)
  .setThumbnail('attachment://nameOfYourPicture');
message.channel.send(embed);

Post a Comment for "How To Use Local File As Thumbnail In DiscordJS Embedded Message?"