Daniet Cinema
Daniet Cinema
DIAdiscord.js - Imagine an app
Created by Daniet Cinema on 12/21/2024 in #djs-questions
Image on embed message
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,
});
})();
5 replies
DIAdiscord.js - Imagine an app
Created by Daniet Cinema on 12/21/2024 in #djs-questions
Image on embed message
I do attachments: [] otherwise I get the image duplicated
5 replies