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

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
8 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
vance_
vance_OP2y ago
my code:
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}
`)
]
})
}
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
pat
pat2y ago
what is this exact link
vance_
vance_OP2y ago
it makes a spotify card api basically
pat
pat2y ago
what is this exact link nvm it's not a png or jpeg so it gets rejected
vance_
vance_OP2y ago
https://api.aniket091.xyz/spotifycard?name=Hot%20N%20Cold&artists=Katy%20Perry&image=https://i.scdn.co/image/ab67616d0000b273df35c65d88dfacb5798f7291&elapsedtime=118256&totaltime=220226 ah how shall i make it into a PNG? because I really do want it in my .setImage() thing alright, thanks a lot @qjuh so I made a few changes, I added:
const buffer = await fetch(URL)

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

const attachment = new AttachmentBuilder(buffer, {
name: "spotify.png",
})
and then .setImage(attachment)
d.js docs
d.js docs2y ago
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]
+ });
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]
+ });
vance_
vance_OP2y ago
ah alright so I have to do
attachment://${attachment.name}
attachment://${attachment.name}
thats it? yep @qjuh I did what you said but now its throwing another error smh
TypeError [ReqResourceType]: The resource must be a string, Buffer or a valid file stream.
TypeError [ReqResourceType]: The resource must be a string, Buffer or a valid file stream.
code for reference:
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]
})
}
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]
})
}
hmm, how do I make it into a buffer? im sorry this is my first time working with attachment builders nevermind i fixed it by making the buffer the url itself
Want results from more Discord servers?
Add your server