Discord Command

Hi everyone, i have a problem with my code. When i did the command, the image does not appear on the embed and i don’t really know why. Here is the code:
21 Replies
d.js toolkit
d.js toolkit4w ago
d.js docs
d.js docs4w ago
Files in embeds should be attached via the message option object and referenced in the embed:
const attachment = new AttachmentBuilder('./image.png', { name: 'image1.png' });
const embed = new EmbedBuilder()
.setTitle('Attachments')
.setImage(`attachment://${attachment.name}`);

channel.send({
embeds: [embed],
files: [attachment]
});
const attachment = new AttachmentBuilder('./image.png', { name: 'image1.png' });
const embed = new EmbedBuilder()
.setTitle('Attachments')
.setImage(`attachment://${attachment.name}`);

channel.send({
embeds: [embed],
files: [attachment]
});
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
oh so i have to let the message?
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
can i use this command and the embed will be send on another channel how
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
then even the message is deleted, the image will be on the embed
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
ok i can try it with my code without add this thing, i just need to remove the deleted message on the code
const { EmbedBuilder, PermissionFlagsBits, AttachmentBuilder } = require('discord.js');

module.exports = {
name: 'preset',
description: 'Partager un preset Bakkesmod avec une image',
usage: '<code_bakkesmod> [+ image attachée]',
aliases: ['bm', 'bakkesmod'],
permissions: [PermissionFlagsBits.ManageMessages],
cooldown: 5,

async execute(message, args, client) {
const config = client.config;

if (!args[0]) {
return message.reply(`${config.emojis.error} Usage: \`!preset <code_bakkesmod>\` + attache une image du preset`);
}

const presetCode = args.join(' ');
const attachment = message.attachments.first();

if (!attachment) {
return message.reply(`${config.emojis.error} Tu dois attacher une image de ton preset !`);
}

if (!attachment.contentType?.startsWith('image/')) {
return message.reply(`${config.emojis.error} Le fichier attaché doit être une image !`);
}

// Télécharger l'image AVANT de supprimer le message
const response = await fetch(attachment.url);
const buffer = await response.arrayBuffer();
const imageAttachment = new AttachmentBuilder(Buffer.from(buffer), { name: 'preset.png' });

const presetEmbed = new EmbedBuilder()
.setTitle(':red_car: Preset Bakkesmod')
.setDescription(`\`\`\`\n${presetCode}\n\`\`\``)
.setColor(config.bot.color)
.setImage('attachment://preset.png')
.setFooter({ text: `Preset fait par ${message.author.tag}` })
.setTimestamp();

// Maintenant on peut supprimer le message
await message.delete().catch(() => {});

// Envoyer l'embed avec l'image téléchargée
await message.channel.send({
embeds: [presetEmbed],
files: [imageAttachment]
});
}
};
const { EmbedBuilder, PermissionFlagsBits, AttachmentBuilder } = require('discord.js');

module.exports = {
name: 'preset',
description: 'Partager un preset Bakkesmod avec une image',
usage: '<code_bakkesmod> [+ image attachée]',
aliases: ['bm', 'bakkesmod'],
permissions: [PermissionFlagsBits.ManageMessages],
cooldown: 5,

async execute(message, args, client) {
const config = client.config;

if (!args[0]) {
return message.reply(`${config.emojis.error} Usage: \`!preset <code_bakkesmod>\` + attache une image du preset`);
}

const presetCode = args.join(' ');
const attachment = message.attachments.first();

if (!attachment) {
return message.reply(`${config.emojis.error} Tu dois attacher une image de ton preset !`);
}

if (!attachment.contentType?.startsWith('image/')) {
return message.reply(`${config.emojis.error} Le fichier attaché doit être une image !`);
}

// Télécharger l'image AVANT de supprimer le message
const response = await fetch(attachment.url);
const buffer = await response.arrayBuffer();
const imageAttachment = new AttachmentBuilder(Buffer.from(buffer), { name: 'preset.png' });

const presetEmbed = new EmbedBuilder()
.setTitle(':red_car: Preset Bakkesmod')
.setDescription(`\`\`\`\n${presetCode}\n\`\`\``)
.setColor(config.bot.color)
.setImage('attachment://preset.png')
.setFooter({ text: `Preset fait par ${message.author.tag}` })
.setTimestamp();

// Maintenant on peut supprimer le message
await message.delete().catch(() => {});

// Envoyer l'embed avec l'image téléchargée
await message.channel.send({
embeds: [presetEmbed],
files: [imageAttachment]
});
}
};
this can work?
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
but it can download the image
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
i just tried this and it works
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
oh
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
the image will not become like this 💩 ?
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Neyzzou
NeyzzouOP4w ago
ok ty
d.js toolkit
d.js toolkit4w ago
The thread owner has marked this issue as solved.

Did you find this page helpful?