Attachment won't send

Hello everyone, again, so this time i encountered an issue where when i take attachment as an option I cannot output it. Code:
const { SlashCommandBuilder, EmbedBuilder } = require(`discord.js`);

module.exports = {
data: new SlashCommandBuilder()
.setName(`sbapply`)
.setDescription(`Applies for starboard.`)
.addAttachmentOption((option) =>
option
.setName(`image`)
.setDescription(`The image for starboard`)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName(`message`)
.setDescription(`The message to send along side the application`)
),

async execute(interaction, client) {
let message = interaction.options.getString(`message`);
const attachment = interaction.options.getAttachment(`image`);
const channel1 = client.channels.cache.get(`1285686651351334912`);
//const channel2 = client.channels.cache.get(`1284928279832428605`);

if (!message) message = `No message was provided with the application`;

const embed = new EmbedBuilder()
.setTitle(attachment.name)
.setDescription(message)
.setImage(attachment);

await interaction.reply({
content: `Applied successfully`,
embeds: [embed],
ephemeral: true,
});

await channel1.send({
embeds: [embed],
});
},
};
const { SlashCommandBuilder, EmbedBuilder } = require(`discord.js`);

module.exports = {
data: new SlashCommandBuilder()
.setName(`sbapply`)
.setDescription(`Applies for starboard.`)
.addAttachmentOption((option) =>
option
.setName(`image`)
.setDescription(`The image for starboard`)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName(`message`)
.setDescription(`The message to send along side the application`)
),

async execute(interaction, client) {
let message = interaction.options.getString(`message`);
const attachment = interaction.options.getAttachment(`image`);
const channel1 = client.channels.cache.get(`1285686651351334912`);
//const channel2 = client.channels.cache.get(`1284928279832428605`);

if (!message) message = `No message was provided with the application`;

const embed = new EmbedBuilder()
.setTitle(attachment.name)
.setDescription(message)
.setImage(attachment);

await interaction.reply({
content: `Applied successfully`,
embeds: [embed],
ephemeral: true,
});

await channel1.send({
embeds: [embed],
});
},
};
Node version: v22.9.0 Discord.js version: [email protected]
13 Replies
d.js toolkit
d.js toolkit5mo 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 OP
d.js docs
d.js docs5mo 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]
});
Nein! Ich bin nicht Alex!
never mind thanks okay after another test doing
const embed = new EmbedBuilder()
.setTitle(`${attachment.name`})
.setImage(`attachment://${attachment.name}`)
const embed = new EmbedBuilder()
.setTitle(`${attachment.name`})
.setImage(`attachment://${attachment.name}`)
is the same as
const attachmentBuild(`./${attachment}`, {name: `$attachment.name`})
const embed = new EmbedBuilder()
.setTitle(`${attachmentBuild.name`})
.setImage(`attachmentBuild://${attachment.name}`)
const attachmentBuild(`./${attachment}`, {name: `$attachment.name`})
const embed = new EmbedBuilder()
.setTitle(`${attachmentBuild.name`})
.setImage(`attachmentBuild://${attachment.name}`)
still doesnt show the image
Mark
Mark5mo ago
Show the full send method
Nein! Ich bin nicht Alex!
const {
SlashCommandBuilder,
EmbedBuilder,
AttachmentBuilder,
} = require(`discord.js`);

module.exports = {
data: new SlashCommandBuilder()
.setName(`sbapply`)
.setDescription(`Applies for starboard.`)
.addAttachmentOption((option) =>
option
.setName(`image`)
.setDescription(`The image for starboard`)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName(`message`)
.setDescription(`The message to send along side the application`)
),

async execute(interaction, client) {
let message = interaction.options.getString(`message`);
const attachment = interaction.options.getAttachment(`image`);
const attachmentUse = new AttachmentBuilder(`./${attachment}`, {
name: `${attachment.name}`,
});
const channel1 = client.channels.cache.get(`1285686651351334912`);
//const channel2 = client.channels.cache.get(`1284928279832428605`);

if (!message) message = `No message was provided with the application`;

const embed = new EmbedBuilder()
.setTitle(attachmentUse.name)
.setDescription(message)
.setImage(`attachment://${attachmentUse.name}`);

await interaction.reply({
content: `Applied successfully`,
embeds: [embed],
ephemeral: true,
});

await channel1.send({
embeds: [embed],
});
},
};
const {
SlashCommandBuilder,
EmbedBuilder,
AttachmentBuilder,
} = require(`discord.js`);

module.exports = {
data: new SlashCommandBuilder()
.setName(`sbapply`)
.setDescription(`Applies for starboard.`)
.addAttachmentOption((option) =>
option
.setName(`image`)
.setDescription(`The image for starboard`)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName(`message`)
.setDescription(`The message to send along side the application`)
),

async execute(interaction, client) {
let message = interaction.options.getString(`message`);
const attachment = interaction.options.getAttachment(`image`);
const attachmentUse = new AttachmentBuilder(`./${attachment}`, {
name: `${attachment.name}`,
});
const channel1 = client.channels.cache.get(`1285686651351334912`);
//const channel2 = client.channels.cache.get(`1284928279832428605`);

if (!message) message = `No message was provided with the application`;

const embed = new EmbedBuilder()
.setTitle(attachmentUse.name)
.setDescription(message)
.setImage(`attachment://${attachmentUse.name}`);

await interaction.reply({
content: `Applied successfully`,
embeds: [embed],
ephemeral: true,
});

await channel1.send({
embeds: [embed],
});
},
};
i sent the full code if thats okay
Mark
Mark5mo ago
And where are you attaching the files like it explains in the tag
Nein! Ich bin nicht Alex!
oh the files: [attachmentUse] //in my case? yeah tried it too does not work it just replies and then makes an error
Mark
Mark5mo ago
Which is... Because not doing it correctly sure isn't going to make it work. If you get an error while trying to use the correct method, you need to address the error, not revert to a non working method
Nein! Ich bin nicht Alex!
okay so currently the error with the attachment is fixed the other error is just a InteractionAlreadyReplied i do not know why it didnt work first time it might have been me forgetting to npm run test after the changes of course theres a nevermind in this
Error: ENOENT: no such file or directory, stat '/home/alex/workspace/project-x-security-bot/[object Object]'
at async Object.stat (node:internal/fs/promises:1032:18)
at async resolveFile (/home/alex/workspace/project-x-security-bot/node_modules/discord.js/src/util/DataResolver.js:100:19)
at async MessagePayload.resolveFile (/home/alex/workspace/project-x-security-bot/node_modules/discord.js/src/structures/MessagePayload.js:294:35)
at async Promise.all (index 0)
at async MessagePayload.resolveFiles (/home/alex/workspace/project-x-security-bot/node_modules/discord.js/src/structures/MessagePayload.js:259:18)
at async TextChannel.send (/home/alex/workspace/project-x-security-bot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:176:29)
at async Object.execute (/home/alex/workspace/project-x-security-bot/src/commands/starboard/sbapply.js:39:5)
at async Object.execute (/home/alex/workspace/project-x-security-bot/src/events/client/interactionCreate.js:14:9) {
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: '/home/alex/workspace/project-x-security-bot/[object Object]'
}
Error: ENOENT: no such file or directory, stat '/home/alex/workspace/project-x-security-bot/[object Object]'
at async Object.stat (node:internal/fs/promises:1032:18)
at async resolveFile (/home/alex/workspace/project-x-security-bot/node_modules/discord.js/src/util/DataResolver.js:100:19)
at async MessagePayload.resolveFile (/home/alex/workspace/project-x-security-bot/node_modules/discord.js/src/structures/MessagePayload.js:294:35)
at async Promise.all (index 0)
at async MessagePayload.resolveFiles (/home/alex/workspace/project-x-security-bot/node_modules/discord.js/src/structures/MessagePayload.js:259:18)
at async TextChannel.send (/home/alex/workspace/project-x-security-bot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:176:29)
at async Object.execute (/home/alex/workspace/project-x-security-bot/src/commands/starboard/sbapply.js:39:5)
at async Object.execute (/home/alex/workspace/project-x-security-bot/src/events/client/interactionCreate.js:14:9) {
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: '/home/alex/workspace/project-x-security-bot/[object Object]'
}
const {
SlashCommandBuilder,
EmbedBuilder,
AttachmentBuilder,
} = require(`discord.js`);

module.exports = {
data: new SlashCommandBuilder()
.setName(`sbapply`)
.setDescription(`Applies for starboard.`)
.addAttachmentOption((option) =>
option
.setName(`image`)
.setDescription(`The image for starboard`)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName(`message`)
.setDescription(`The message to send along side the application`)
),

async execute(interaction, client) {
let message = interaction.options.getString(`message`);
const attachment = interaction.options.getAttachment(`image`);
const attachmentUse = new AttachmentBuilder(`./${attachment}`, {
name: `${attachment.name}`,
});
const channel1 = client.channels.cache.get(`1285686651351334912`);
//const channel2 = client.channels.cache.get(`1284928279832428605`);

if (!message) message = `No message was provided with the application`;

const embed = new EmbedBuilder()
.setTitle(attachmentUse.name)
.setDescription(message)
.setImage(`attachment://${attachmentUse.name}`);

await interaction.reply({
content: `Applied successfully`,
embeds: [embed],
files: [file],
ephemeral: true,
});

await channel1.send({
embeds: [embed],
files: [file],
});
},
};
const {
SlashCommandBuilder,
EmbedBuilder,
AttachmentBuilder,
} = require(`discord.js`);

module.exports = {
data: new SlashCommandBuilder()
.setName(`sbapply`)
.setDescription(`Applies for starboard.`)
.addAttachmentOption((option) =>
option
.setName(`image`)
.setDescription(`The image for starboard`)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName(`message`)
.setDescription(`The message to send along side the application`)
),

async execute(interaction, client) {
let message = interaction.options.getString(`message`);
const attachment = interaction.options.getAttachment(`image`);
const attachmentUse = new AttachmentBuilder(`./${attachment}`, {
name: `${attachment.name}`,
});
const channel1 = client.channels.cache.get(`1285686651351334912`);
//const channel2 = client.channels.cache.get(`1284928279832428605`);

if (!message) message = `No message was provided with the application`;

const embed = new EmbedBuilder()
.setTitle(attachmentUse.name)
.setDescription(message)
.setImage(`attachment://${attachmentUse.name}`);

await interaction.reply({
content: `Applied successfully`,
embeds: [embed],
files: [file],
ephemeral: true,
});

await channel1.send({
embeds: [embed],
files: [file],
});
},
};
Mark
Mark5mo ago
I think it's trying to look for it on your computer because of how you structure the builder You should be able to use the attachment URL and pass that to the builder
Nein! Ich bin nicht Alex!
im a complete newbie in discord.js so idk how to get the URL, since the user chooses the attachment
Mark
Mark5mo ago
The docs tell you what getAttachment returns, and it has a clickable link that if you follow will show you all the properties of the object
Nein! Ich bin nicht Alex!
okay so- thank you a lot ill mark this as solved

Did you find this page helpful?