#not really djs related but lets talk here

1 messages · Page 1 of 1 (latest)

regal granite
#

how is the image returned?

nova crown
regal granite
#

no, like if you use axios, jquery or a library like these ones, how is the image returned, as a buffer or how exactly

nova crown
#

@regal granite

#

this is how the data is returned

regal granite
#

I think it is base64 encoding, make a buffer from it using Buffer.from(<Data>, 'base64') and then make it an attachment with AttachmentBuilder and send it

#

for now send it like that so we can see if it works

nova crown
#

nah man it didnt work @regal granite

regal granite
#

binary encoding?

#

wait, show me the code

nova crown
#
let data;
await axios.get(`https://apiv2.spapi.ga/image/triggered?image=https://cdn.discordapp.com/avatars/1017416456897560588/fc0b1df1086899bb1eeadfe6766c4e75.png`).then(res => {
      data=Buffer.from(res.data, "base64")
    })

    const attachment = new AttachmentBuilder(data, {name: "image.png"})

    await message.reply({embeds: [new EmbedBuilder().setImage("attachment://image.png")], files: [attachment]})
regal granite
#

🤔 is data the buffer?

#

log it so we can be sure

nova crown
nova crown
regal granite
#

idk, try with binary

nova crown
nova crown
regal granite
#

we need to find the right encoding and it will work

nova crown
#

or I could say broken image

regal granite
#

if the image isn't showing 💩, I think the problem is from the api

#

at least I tried to help you :D

nova crown
nova crown
regal granite
#

try with utf-8 encoding, idk how encoding really works soo @nova crown

regal granite
#

I have no more ideas dogeHaHa

regal granite
#

try this

nova crown
#

k

regal granite
#

set it to binary and then base64 if it doesn't work

nova crown
regal granite
#

yeah, then log the response, I think it will return the actual buffer

#

so you'll not have to make it a buffer again

#

I think

nova crown
#

okay imma try

#

it worked @regal granite

#

you are an angel man

regal granite
#

:D

nova crown
#
const response = await axios.request({
      method: 'GET',
      url: 'https://apiv2.spapi.ga/image/triggered?image=https://cdn.discordapp.com/avatars/1017416456897560588/fc0b1df1086899bb1eeadfe6766c4e75.png',
      responseType: 'arraybuffer',
      responseEncoding: 'base64'
    });
    console.log(response.data);

    const attachment = new AttachmentBuilder(response.data, {name: "image.png"})

    await message.reply({embeds: [new EmbedBuilder().setImage("attachment://image.png")], files: [attachment]})
#

this worked