#Invalid Form Body embeds[0].image.url[URL_TYPE_INVALID_URL] Not a well formed URL?

36 messages · Page 1 of 1 (latest)

median belfry
#

So i'm trying to request a custom image from a website and the res says that it is 200 (OK) but even then I'm getting this error which is preventing me from using the res recieved in a .setImage() function in my EmbedBuilder

ornate fractal
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

median belfry
#

my code: ```js
const e = user2.presence.activities
const duration = e[0].timestamps.end.getTime() - e[0].timestamps.start.getTime()
const f = String(e[0].assets.largeImage).slice(8)
const elapsed = Date.now() - e[0].timestamps.start.getTime()
const image = https://i.scdn.co/image/${String(e[0].assets.largeImage).slice(8)}
const URL = https://api.aniket091.xyz/spotifycard?name=${e[0].details}&artists=${e[0].state}&image=${image}&elapsedtime=${elapsed}&totaltime=${duration}&key=xyz

await fetch(URL).then((res) => console.log(res))
if (interaction.user.id === client.config.adminId) {
interaction.channel.send({
embeds: [
new EmbedBuilder()
.setImage(URL)
.setDescription( Details: ${e[0].details} Elapsed Time: ${formatDuration(Date.now() - e[0].timestamps.start.getTime())} Start Time: ${e[0].timestamps.start.getTime()} End Time: ${e[0].timestamps.end.getTime()} Duration: ${formatDuration(duration)} Album: ${e[0].assets.largeText} Author: ${e[0].state})
]
})
}

#

and when I visit the exact link (the res console logs it), everything is normal

#

node: 17.9.0

wraith cloud
#

what is this exact link

median belfry
#

it makes a spotify card

#

api

#

basically

wraith cloud
#

what is this exact link

#

nvm

#

it's not a png or jpeg so it gets rejected

median belfry
#

https://api.aniket091.xyz/spotifycard?name=Hot%20N%20Cold&artists=Katy%20Perry&image=https://i.scdn.co/image/ab67616d0000b273df35c65d88dfacb5798f7291&elapsedtime=118256&totaltime=220226

median belfry
median belfry
#

because I really do want it in my .setImage() thing

stuck flame
#

You already fetched the file, make that into a Buffer, add it in an AttachmentBuilder and use that

median belfry
#

@stuck flame so I made a few changes, I added:

#
  const buffer = await fetch(URL)

        const attachment = new AttachmentBuilder(buffer, {
            name: "spotify.png",
        })
#

and then

#

.setImage(attachment)

wicked valleyBOT
#

MessageEmbed#attachFiles has been removed. Files should be attached via the message option object instead:

  const attachment = new MessageAttachment('./image.png', 'image1.png');
  const embed = new MessageEmbed()
-   .attachFiles([attachment])
    .setTitle('Attachments')
    .setImage(`attachment://${attachment.name}`);

- channel.send(embed)
+ channel.send({
+   embeds: [embed],
+   files: [attachment]
+ });
stuck flame
#

Ignore the v13 classes, but apart from that it‘s accurate

median belfry
#

ah alright

#

thats it?

stuck flame
#

And attach the attachment in the files: when sending

median belfry
#

@stuck flame I did what you said but now its throwing another error smh

#

code for reference: ```js
if (interaction.user.id === client.config.adminId) {
const buffer = await fetch(URL)

    const attachment = new AttachmentBuilder(buffer, {
        name: "spotify.png",
    })

interaction.channel.send({
embeds: [
new EmbedBuilder()
.setImage(attachment://${attachment.name})
.setDescription( Details: ${e[0].details} Elapsed Time: ${formatDuration(Date.now() - e[0].timestamps.start.getTime())} Start Time: ${e[0].timestamps.start.getTime()} End Time: ${e[0].timestamps.end.getTime()} Duration: ${formatDuration(duration)} Album: ${e[0].assets.largeText} Author: ${e[0].state})
],
files: [attachment]
})
}

stuck flame
#

Because the result from fetch is not a Buffer. Just because you call your variable buffer doesn’t make it one

median belfry
#

im sorry this is my first time working with attachment builders

stuck flame
#

Depends on what fetch is here… is it node‘s own fetch? Is it an external package? Either of those should have documentation telling you how

median belfry
#

nevermind