Michal__d
Michal__d
DIAdiscord.js - Imagine an app
Created by Michal__d on 11/19/2024 in #djs-questions
Embed image doesn't show since couple of days.
I am not sure if it is discord.js problem. My bot once a day posts 3 embeds with images. In 2 of 3 embeds images are displayed correctly, in last embed image is not displayed at all since 5 days. I checked embed source, image url and proxy_url are set correctly, however image width and height is 0. When i open that image url (from not working embed) in the browser it clearly shows image is 560 x 400 px. When i open image from working embed it shows the same thing. Even weirder is that, if i request exactly the same embed with slash command, it displays image correctly, problem exists only with automated posts with cron. discord.js - 14.16.3 node.js - 20.16.0 OS - Ubuntu 20.04
const embed = new EmbedBuilder()
.setColor('#cc0000')
.setThumbnail(`${basePath}/icon.png`)
.setImage(`${basePath}/locations/${id.toLowerCase()}.png`);

const sentMessage = await channel
.send({
embeds: [embed],
})
.catch(console.log);
const embed = new EmbedBuilder()
.setColor('#cc0000')
.setThumbnail(`${basePath}/icon.png`)
.setImage(`${basePath}/locations/${id.toLowerCase()}.png`);

const sentMessage = await channel
.send({
embeds: [embed],
})
.catch(console.log);
Is there any way i can force width and height of that image inside embed?
4 replies
DIAdiscord.js - Imagine an app
Created by Michal__d on 10/21/2022 in #djs-questions
Image outside embed, only when image is a buffer.
Node.js 16.18.0 discord.js 14.6.0 After update discord.js from 13.9.2 to 14.6.0 images are not inside embed anymore. (no errors)
import { AttachmentBuilder, EmbedBuilder } from 'discord.js';

const stats = async (client, interaction) => {
const imageBuffer = await createChart(/*<chart data>*/);
const attachment = new AttachmentBuilder(imageBuffer, 'chart.jpg');
const embed = new EmbedBuilder()
.setImage('attachment://chart.jpg');

interaction.reply({
embeds: [embed],
files: [attachment]
});
};
import { AttachmentBuilder, EmbedBuilder } from 'discord.js';

const stats = async (client, interaction) => {
const imageBuffer = await createChart(/*<chart data>*/);
const attachment = new AttachmentBuilder(imageBuffer, 'chart.jpg');
const embed = new EmbedBuilder()
.setImage('attachment://chart.jpg');

interaction.reply({
embeds: [embed],
files: [attachment]
});
};
createChart creates image buffer, and i am sure image is correct, nothing changed here. Image buffer type is image/png When i replace image buffer to image path that already exists in data folder everything works as on d.js 13.9.2, image is inside embed.
const attachment = new AttachmentBuilder(imageBuffer, 'chart.jpg');
const attachment = new AttachmentBuilder(imageBuffer, 'chart.jpg');
to:
const attachment = new AttachmentBuilder(path.join(process.cwd(), 'data/chart.jpg'), 'chart.jpg');
const attachment = new AttachmentBuilder(path.join(process.cwd(), 'data/chart.jpg'), 'chart.jpg');
I know guide is a little outdated, but shows exactly the same code https://discordjs.guide/popular-topics/embeds.html#resending-and-editing What i am missing?
4 replies