Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

292
Views
Discord - Add image from Google Drive in Embed Message

I have a list of files that I'm retrieving from Drive:

const list = await drive.files.list({
  q: `parents in '${process.env.DRIVE_DIR}' and name contains 'test_'`,
  spaces: 'drive',
  fields: 'files(id, mimeType, webViewLink)'
})

After getting the files I want to send embed messages with the image from Drive:

const embed = new MessageEmbed()
  .setColor('#6adada')
  .setTitle('Test')
  .setImage(list.data.files[index].webViewLink)
message.channel.send({embeds: [embed]})

I checked all permission on Google Drive and they are correct, if I access the link as a guest I can see the image in the browser. Is there something that I'm missing? Thanks in advance.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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)
about 4 years ago · Juan Pablo Isaza Report

0

You need to send the webViewLink to discord, where you change the usp query parameter in the URL from drivesdk to sharing.

For reference, this is the discord incoming webhook API: https://discord.com/developers/docs/resources/webhook#execute-webhook

the google drive rest API: https://developers.google.com/drive/api/v3/reference/files#resource

Check out a simple implementation of it here:

Example Implementation                                                                                 Run in Fusebit
const { Integration } = require('@fusebit-int/framework');
const superagent = require('superagent')

const integration = new Integration();
const router = integration.router;
const googleConnector = 'googleConnector';
const discordConnector = 'discordConnector';
router.post('/api/tenant/:tenantId/test', async (ctx) => {
  try {
    const googleClient = await integration.tenant.getSdkByTenant(ctx, googleConnector, ctx.params.tenantId);

  const files = await googleClient
    .drive({
      version: 'v3',
    })
    .files.list({fields: 'files(id, mimeType, webViewLink)'});
  const file = files.data.files[0]
  file.webViewLink = file.webViewLink.replace('drivesdk', 'sharing')
  await discordSendMessage(ctx, file.webViewLink)
  ctx.body = {
    message: `Message with embed sent to discord.`,
  };
  } catch (e) {console.log(e)}
  
});

async function discordSendMessage(ctx, content) {
  const discordClient = await integration.tenant.getSdkByTenant(
    ctx,
    discordConnector,
    ctx.params.tenantId
  );
  const webhook = discordClient?.fusebit?.credentials?.webhook;
  if (!webhook) {
    ctx.throw(404, `The installation does not have a default webhook channel.`);
  }
  try {
  return await superagent.post(webhook.url).send({ content })} catch (e) {console.log(e)}
}

module.exports = integration;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!