最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use local file as thumbnail in DiscordJS embedded message? - Stack Overflow

programmeradmin5浏览0评论

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) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1):  
DiscordAPIError: Invalid Form Body 
embed.thumbnail.url: Not a well formed URL.

Normal URL's do work however.

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) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1):  
DiscordAPIError: Invalid Form Body 
embed.thumbnail.url: Not a well formed URL.

Normal URL's do work however.

Share Improve this question asked Oct 13, 2017 at 16:46 HedvaHedva 3471 gold badge4 silver badges17 bronze badges 2
  • Send the proper url of the file. https://example./img/025.png – user2652134 Commented Oct 13, 2017 at 17:39
  • This was not an option for me. Some images were generated at the same moment, and they're not stored on any server. But I already got an answer :) (below). – Hedva Commented Oct 19, 2017 at 17:44
Add a ment  | 

2 Answers 2

Reset to default 7

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'
  }]
});

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);
发布评论

评论列表(0)

  1. 暂无评论