久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 人成久久 | 日本三级电影在线看 | 成人毛片网站 | 97国产超碰 | 欧美视频1 | 欧美高清视频一区 | 色毛片| 国产精品久久久乱弄 | 亚洲3级 | 国产日韩免费视频 | 精产国产伦理一二三区 | 亚洲免费一区二区 | 日韩在线| 最新国产精品 | 亚洲网站在线观看 | 欧美成人猛片aaaaaaa | 久久久久黄色 | 精品美女在线观看视频在线观看 | 欧美在线小视频 | 国产精品久久久久久久久久久久冷 | 成人国产精品久久 | 一区二区在线观看免费视频 | 成人av网站在线观看 | 亚洲第一av| 日韩国产一区 | 第四色影音先锋 | 成人在线精品 | 国产99久久精品一区二区永久免费 | 久久99精品国产麻豆婷婷 | 久久亚洲经典 | 亚洲色图50p| 久久亚洲国产 | 久久大 | 久久av资源网 | 色在线免费 | 亚洲国产aⅴ成人精品无吗 综合国产在线 | 亚洲在线一区二区 | 亚洲一区二区中文字幕 | 国产精品久久久久一区二区三区 | 国产高清一区二区三区 | 国产三级网站 |