Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

284
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda