Images not loading in embed

So if you are trying to setImage() a image from a discord chat, it will just not load it, but if you are trying to load it from a different URL ( domain ) it will work
14 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
treble/luna
treble/luna12mo ago
show your code
GeavaDev
GeavaDevOP12mo ago
No description
GeavaDev
GeavaDevOP12mo ago
client.on('messageCreate', async (message) => {
if (message.author.bot || !message.guild) return;

if (message.attachments.size > 0) {
Pointing.findOne({ userid: message.author.id }, async (err, res) => {
if (err) return console.log(err)
if (res) {
res.points = res.points + parseInt(user_config.points_per_image)
res.save()
} else {
const newdoc = new Pointing({
userid: message.author.id,
points: parseInt(user_config.points_per_image),
})
newdoc.save()
}
})

const adminChannel = message.guild.channels.cache.find(channel => channel.id == user_config.admin_channel);
if (adminChannel) {
const imageButtonRow = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId('scadePuncte')
.setLabel('Scoate Punctele')
.setStyle('Danger'),
);
const urlParts = message.attachments.first().url.split('?');
const extractedUrl = urlParts[0];
const imageEmbed = new Discord.EmbedBuilder()
.setTitle('Image from user')
.setDescription(`Image Link: ${extractedUrl}`)
.setColor("Green")
.setFooter({ text: `User: ${message.author.id}` });


adminChannel.send({ embeds: [imageEmbed], components: [imageButtonRow] });
}
}
});
client.on('messageCreate', async (message) => {
if (message.author.bot || !message.guild) return;

if (message.attachments.size > 0) {
Pointing.findOne({ userid: message.author.id }, async (err, res) => {
if (err) return console.log(err)
if (res) {
res.points = res.points + parseInt(user_config.points_per_image)
res.save()
} else {
const newdoc = new Pointing({
userid: message.author.id,
points: parseInt(user_config.points_per_image),
})
newdoc.save()
}
})

const adminChannel = message.guild.channels.cache.find(channel => channel.id == user_config.admin_channel);
if (adminChannel) {
const imageButtonRow = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId('scadePuncte')
.setLabel('Scoate Punctele')
.setStyle('Danger'),
);
const urlParts = message.attachments.first().url.split('?');
const extractedUrl = urlParts[0];
const imageEmbed = new Discord.EmbedBuilder()
.setTitle('Image from user')
.setDescription(`Image Link: ${extractedUrl}`)
.setColor("Green")
.setFooter({ text: `User: ${message.author.id}` });


adminChannel.send({ embeds: [imageEmbed], components: [imageButtonRow] });
}
}
});
so basically in the first image im using a custom url ( from a image uploader website ) but in my code, im just forwarding the image that the user is sending in the embed message and yes, i extracted the direct link of the image and it ends in its format like image.png link example "https://cdn.discordapp.com/attachments/1200142807969583144/1200157639481491686/arthur.PNG"
treble/luna
treble/luna12mo ago
i dont see any setImage in that embedbuilder
GeavaDev
GeavaDevOP12mo ago
oh sorry, i removed it i think let me readdit
GeavaDev
GeavaDevOP12mo ago
No description
GeavaDev
GeavaDevOP12mo ago
its not showing either but at least i added something in the description lol
treble/luna
treble/luna12mo ago
just adding your image in the description wont show it you have to use .setImage()
GeavaDev
GeavaDevOP12mo ago
console.log(urlParts[0])
const imageEmbed = new Discord.EmbedBuilder()
.setTitle('Image from user')
.setImage(`${extractedUrl}`)
.setDescription(`Image Link: ${extractedUrl}`)
.setColor("Green")
.setFooter({ text: `User: ${message.author.id}` });

console.log(urlParts[0])
const imageEmbed = new Discord.EmbedBuilder()
.setTitle('Image from user')
.setImage(`${extractedUrl}`)
.setDescription(`Image Link: ${extractedUrl}`)
.setColor("Green")
.setFooter({ text: `User: ${message.author.id}` });

` sorry, i forgot to resend yes, i've added as i said it seems to not work for the images with the discord domain, for other domains its working
treble/luna
treble/luna12mo ago
discord images now expire after x amount of times however, this is not related to djs as djs does not handle how embeds display images
GeavaDev
GeavaDevOP12mo ago
yes but somehow they removed the display of them from the discord domain and i think its related, i thought it was something in my code at first, then i tried an image from other domain and it worked
treble/luna
treble/luna12mo ago
again, djs does not control how embeds display images #useful-servers ddevs although this url has query params
GeavaDev
GeavaDevOP12mo ago
i filtred it out and i removed the params its just the direct image its fine, i will move over
Want results from more Discord servers?
Add your server