2017-10-13 52 views
0

是否可以使用本地文件作爲帶DiscordJs的嵌入式消息的縮略圖?如何在DiscordJS嵌入消息中使用本地文件作爲縮略圖?

"thumbnail": { 
    "url": "../img/025.png" 
}, 

這似乎並不奏效。

(node:34721) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): 
DiscordAPIError: Invalid Form Body 
embed.thumbnail.url: Not a well formed URL. 

然而,正常的URL可以正常工作。

+0

發送文件的正確的URL。 'https:// example.com/img/025.png' –

+0

這不是我的選擇。有些圖像是在同一時間生成的,並且不存儲在任何服務器上。但我已經得到了答案:)(下圖)。 – Hedva

回答

0

我已經找到了答案。 鏈接到文件的正確URL不是我的選擇,因爲生成了一些圖像。

您可以將圖片附加到郵件中,並將此附件用作縮略圖。 最基本的例子:

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" 
    } 
    }; 

圖像附加到按摩:

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