Discord - Add image from Google Drive in Embed Message
I solved this issue using FS to download the file from drive, after that attaching it to the embed message using the attachment
path in the setImage
function. So after getting the list
of files, I download it (in my case it will be always one file):
const { data } = await drive.files.get(
{
fileId: list.data.files[0].id,
alt: "media"
},
{ responseType: "stream" }
)
const fileName = fID + "." + mimeType.split("/")[1]
const file = fs.createWriteStream(fileName)
data.on("end", () => {
const embed = new MessageEmbed()
.setColor('#6adada')
.setTitle('Test Image')
.setImage('attachment://' + fileName)
message.channel.send({
embeds: [embed],
files: [fileName]
})
.then(() => {
file.end()
fs.unlinkSync(fileName)
})
})
.on("error", error => message.reply(" Error: " + error.message))
.pipe(file)