Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

javascript - 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) 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...