Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda