Image on embed message

Hi, I have a bot that sends an embed message with an image uploaded using AttachmentBuilder The image displays correctly, but when I edit the message ~8 hours later, the image no longer works. Does the image expire? I'm modifying the message with the REST API, so I fetch the message before editing it to retrieve the embed :Thonk:
No description
4 Replies
d.js toolkit
d.js toolkit4d 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!
Daniet Cinema
Daniet CinemaOP4d ago
I do attachments: [] otherwise I get the image duplicated
d.js docs
d.js docs4d ago
:discord: Messages Resource - Edit Message PATCH /channels/channel.id/messages/message.id Edit a previously sent message. The fields content, embeds, and flags can be edited by the original message author. Other users can only edit flags and only if they have the MANAGE_MESSAGES permission in the corresponding channel. When specifying flags, ensure to include all previously set flags/bits in addition to ones that you are modifying. Only flags documented in the table below may be modified by users (unsupported flag changes are currently ignored without error). read more
Daniet Cinema
Daniet CinemaOP3d ago
Thank you for your response 🫡 I’m trying not to use AttachmentBuilder Here’s the test code I’m using, and if I don’t set attachments: [], when I edit the message, I end up with the image both in the embed and in the content of the message, whereas I only want it to appear in the embed Do you know how to fix this? Thank you for your help :yPrayge: Code:
import 'dotenv/config';

import axios from 'axios';
import { randomUUID } from 'crypto';
import { REST, RESTPostAPIChannelMessageResult, Routes } from 'discord.js';
import { RESTPostAPIChannelMessageJSONBody } from 'discord-api-types/v10';

const rest = new REST({
version: '10',
}).setToken(process.env.DISCORD_TOKEN_BOT!);

const sendMessage = async (): Promise<RESTPostAPIChannelMessageResult> => {
const mediaName = `${randomUUID()}.jpg`;

const response = await axios.get(
'https://static-cdn.jtvnw.net/previews-ttv/live_user_emilycc-1920x1080.jpg',
{
responseType: 'arraybuffer',
},
);

const body: RESTPostAPIChannelMessageJSONBody = {
embeds: [
{
image: {
url: `attachment://${mediaName}`,
},
title: 'step 1',
},
],
};

const message = (await rest.post(
Routes.channelMessages('1051883385179611260'),
{
body,
files: [
{
data: response.data,
name: mediaName,
},
],
},
)) as RESTPostAPIChannelMessageResult;

return message;
};

(async (): Promise<void> => {
const message = await sendMessage();

await new Promise((resolve) => setTimeout(resolve, 2500));

await rest.patch(Routes.channelMessage(message.channel_id, message.id), {
body: {
embeds: [
{
...message.embeds[0],
title: 'step 2',
},
],
} satisfies RESTPostAPIChannelMessageJSONBody,
});
})();
import 'dotenv/config';

import axios from 'axios';
import { randomUUID } from 'crypto';
import { REST, RESTPostAPIChannelMessageResult, Routes } from 'discord.js';
import { RESTPostAPIChannelMessageJSONBody } from 'discord-api-types/v10';

const rest = new REST({
version: '10',
}).setToken(process.env.DISCORD_TOKEN_BOT!);

const sendMessage = async (): Promise<RESTPostAPIChannelMessageResult> => {
const mediaName = `${randomUUID()}.jpg`;

const response = await axios.get(
'https://static-cdn.jtvnw.net/previews-ttv/live_user_emilycc-1920x1080.jpg',
{
responseType: 'arraybuffer',
},
);

const body: RESTPostAPIChannelMessageJSONBody = {
embeds: [
{
image: {
url: `attachment://${mediaName}`,
},
title: 'step 1',
},
],
};

const message = (await rest.post(
Routes.channelMessages('1051883385179611260'),
{
body,
files: [
{
data: response.data,
name: mediaName,
},
],
},
)) as RESTPostAPIChannelMessageResult;

return message;
};

(async (): Promise<void> => {
const message = await sendMessage();

await new Promise((resolve) => setTimeout(resolve, 2500));

await rest.patch(Routes.channelMessage(message.channel_id, message.id), {
body: {
embeds: [
{
...message.embeds[0],
title: 'step 2',
},
],
} satisfies RESTPostAPIChannelMessageJSONBody,
});
})();

Did you find this page helpful?