久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 webhook 嵌入中使用 base64 圖像的 discordjs

discordjs using base64 image in webhook embed(在 webhook 嵌入中使用 base64 圖像的 discordjs)
本文介紹了在 webhook 嵌入中使用 base64 圖像的 discordjs的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何使用 webhook 將圖像插入到不和諧嵌入中.我將圖像保存為從數據庫中獲取的 base64 字符串.我試過這個但是我只得到一個空嵌入

How do I insert an image into a discord embed using webhook. I have the image saved as a base64 string which I get from database. I have tried this but I only get an empty embed

const data = b64image.split(',')[1]; 
const buf = new Buffer.from(data, 'base64');
const file = new Discord.MessageAttachment(buf, 'img.jpeg');

const embed = new Discord.MessageEmbed()
    .setImage('attachment://img.jpeg')

webhookClient.send('', {
    username: userName,
    embeds: [embed],
});

推薦答案

我嘗試使用較小的圖像,問題中的代碼有效.所以這是請求大小的問題.我通過設置一個快速路由來提供圖像并使用嵌入中的 URL 來修復它

I tried with a smaller image, and the code in the question worked. So it was a problem with the size of the request. I fixed it by setting up an express route to serve images and used the URL in the embed

router.get('/thumb/:imgId', (req, res) => {
    const imgId = req.params.imgId.toString().trim();
    let file = Buffer.from(b64Image.split(',')[1], 'base64')
    res.status(200);
    res.set('Content-Type', 'image/jpeg');
    res.set('Content-Length', file.length)
    res.send(file)
});

const embed = new Discord.MessageEmbed()
    .setImage(`${base_url}/img/thumb/${imgId}`)
    
webhookClient.send('', {
    username: userName,
    embeds: [embed],
});

這篇關于在 webhook 嵌入中使用 base64 圖像的 discordjs的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 日韩精品一区二区三区在线播放 | 国产欧美一区二区三区在线播放 | 一级黄片一级毛片 | 亚洲一区二区三区视频在线 | 亚洲国产精品99久久久久久久久 | a级黄色网 | 精品一区二区三区四区五区 | 亚洲一区二区av | 日韩精品视频一区二区三区 | 9久9久9久女女女九九九一九 | 99久久99| 91在线视频播放 | 日韩成人免费视频 | 日韩欧美在线视频观看 | 超碰在线人| 毛片免费观看视频 | 老司机午夜性大片 | 一区二区三区四区在线视频 | 中文字幕一区二区三区四区 | 亚洲欧美在线观看 | 欧美在线观看一区 | av中文字幕在线 | 国产婷婷色综合av蜜臀av | 亚洲一区有码 | 国产精品免费播放 | 久草久草久草 | 麻豆久久久久 | 91成人在线 | 精品久久久久久久久久久久久久久久久 | 毛片一区 | 欧美日韩在线成人 | 日韩中文一区 | 老司机精品福利视频 | 亚洲欧美国产精品久久 | 国产高清精品一区二区三区 | 亚洲国产成人精品女人久久久 | 91资源在线| 亚洲精品久久久久中文字幕欢迎你 | 国产视频一区二区 | 国产一区二区在线播放 | 日本a视频|