Add an image buffer as an attachment to an embed

discordjs 14.6.0, nodejs 18.15.0 I'm trying to use a buffer to attach an image to an embed, and I have no clue how I'm supposed to do it. I keep getting different errors, and I might just be an idiot, but the docs don't provide any insight into how I should do this either. The buffer, embed and message aren't the problem. I can save the image to a file or edit the embed into the message without adding the image.
myAttachment = new Discord.AttachmentBuilder(myBuffer, { name: `SPOILER_Example Name.png` });
myEmbed.setImage(`attachment://${myAttachment.name}`);
myMessage.edit({ content: 'Here you go!', embeds: [myEmbed], files: [myAttachment] });
myAttachment = new Discord.AttachmentBuilder(myBuffer, { name: `SPOILER_Example Name.png` });
myEmbed.setImage(`attachment://${myAttachment.name}`);
myMessage.edit({ content: 'Here you go!', embeds: [myEmbed], files: [myAttachment] });
Parts of the error that might be relevant: validator: 's.nullish', given: 'attachment://SPOILER_Example Name.png' ... constraint: 's.string.url', given: 'attachment://SPOILER_Example Name.png', expected: 'expected to match an URL' It appears the url is rejected, but I don't really know what url to provide other than the attachment name. Am I doing something obvious wrong?
6 Replies
d.js toolkit
d.js toolkit11mo 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
Wawajabba
WawajabbaOP11mo ago
Full error
CombinedError: Received one or more errors
at UnionValidator.handle (...\node_modules\@sapphire\shapeshift\dist\index.js:1058:23)
at UnionValidator.parse (...\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (...\node_modules\@discordjs\builders\dist\index.js:245:23)
at Object.solveHtmlRequest [as solveHtml] (...\commands\crosswordgod\mainSolver.js:185:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
errors: [
ValidationError: Expected undefined or null
at NullishValidator.handle (...\node_modules\@sapphire\shapeshift\dist\index.js:718:79)
at NullishValidator.run (...\node_modules\@sapphire\shapeshift\dist\index.js:99:23)
at UnionValidator.handle (...\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (...\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (...\node_modules\@discordjs\builders\dist\index.js:245:23)
at Object.solveHtmlRequest [as solveHtml] (...\commands\crosswordgod\mainSolver.js:185:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
validator: 's.nullish',
given: 'attachment://SPOILER_Example Name.png'
},
CombinedError: Received one or more errors
at UnionValidator.handle (...\node_modules\@sapphire\shapeshift\dist\index.js:1058:23)
at UnionValidator.parse (...\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (...\node_modules\@discordjs\builders\dist\index.js:245:23)
at Object.solveHtmlRequest [as solveHtml] (...\commands\crosswordgod\mainSolver.js:185:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
errors: [
ValidationError: Expected undefined or null
at NullishValidator.handle (...\node_modules\@sapphire\shapeshift\dist\index.js:718:79)
at NullishValidator.run (...\node_modules\@sapphire\shapeshift\dist\index.js:99:23)
at UnionValidator.handle (...\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (...\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (...\node_modules\@discordjs\builders\dist\index.js:245:23)
at Object.solveHtmlRequest [as solveHtml] (...\commands\crosswordgod\mainSolver.js:185:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
validator: 's.nullish',
given: 'attachment://SPOILER_Example Name.png'
},
ExpectedConstraintError: Invalid URL
at Object.run (...\node_modules\@sapphire\shapeshift\dist\index.js:1562:27)
at StringValidator.run (...\node_modules\@sapphire\shapeshift\dist\index.js:103:27)
at UnionValidator.handle (...\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (...\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (...\node_modules\@discordjs\builders\dist\index.js:245:23)
at Object.solveHtmlRequest [as solveHtml] (...\commands\crosswordgod\mainSolver.js:185:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
constraint: 's.string.url',
given: 'attachment://SPOILER_Example Name.png',
expected: 'expected to match an URL'
}
]
}
ExpectedConstraintError: Invalid URL
at Object.run (...\node_modules\@sapphire\shapeshift\dist\index.js:1562:27)
at StringValidator.run (...\node_modules\@sapphire\shapeshift\dist\index.js:103:27)
at UnionValidator.handle (...\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (...\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (...\node_modules\@discordjs\builders\dist\index.js:245:23)
at Object.solveHtmlRequest [as solveHtml] (...\commands\crosswordgod\mainSolver.js:185:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
constraint: 's.string.url',
given: 'attachment://SPOILER_Example Name.png',
expected: 'expected to match an URL'
}
]
}
Toast
Toast11mo ago
You need to remove the spaces in the file name or else it will throw an error about it being an invalid URL, also update d.js to 14.14.1 as that is a really old version by now.
Wawajabba
WawajabbaOP11mo ago
I haven't worked on this bot for a while, but yes I'll update it soon(ish) I had just thought of removing the spaces and that did do the trick... sadly now it still displays outside of the embed 😅 I got it working! There must've been some other character in the actual filename that Discord or djs didn't like 🤷‍♂️, changing it to test.png worked Just removing the whitespace weirdly enough still had it displayed outside of the embed
Toast
Toast11mo ago
sadly now it still displays outside of the embed
it should still display inside embed unless thats a Discord bug.
Wawajabba
WawajabbaOP11mo ago
I guess so? After I removed the spaces the error was gone, but it still wasn't displaying correctly. Anyhow, it works now and I'll just go with a one word filename. Thanks for your help!
Want results from more Discord servers?
Add your server