Bug when using AttachmentBuilder.setSpoiler

I noticed, that it is not possible to set a attachments spoiler with .setSpoiler. I have been told to ask here first, before reporting to GitHub. I also tested the text branch, and it still seems to be there. Steps to reproduce: - use AttachmentBuilder - use a URL as the attachment argument - use setSpoiler function What should happen: Set the spoiler, so the file later gets marked that way in discord. What happens instead: Throws following error:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at new NodeError (/home/phil/Documents/GIT/gurglebot/lib/internal/errors.js:393:5)
at validateString (/home/phil/Documents/GIT/gurglebot/lib/internal/validators.js:161:11)
at parse (/home/phil/Documents/GIT/gurglebot/lib/path.js:1450:5)
at basename (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/util/Util.js:464:15)
at get spoiler [as spoiler] (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/structures/AttachmentBuilder.js:85:12)
at AttachmentBuilder.setSpoiler (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/structures/AttachmentBuilder.js:67:26)
at /home/phil/Documents/GIT/gurglebot/functions/ENGINE/contentWarning/COMPONENT/modal/repost.js:26:16
at /home/phil/Documents/GIT/gurglebot/node_modules/@discordjs/collection/dist/collection.cjs:174:14
at Function.from (<anonymous>)
at Collection.map (/home/phil/Documents/GIT/gurglebot/node_modules/@discordjs/collection/dist/collection.cjs:172:18) {code: 'ERR_INVALID_ARG_TYPE', stack: 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" …cordjs/collection/dist/collection.cjs:172:18)', message: 'The "path" argument must be of type string. Received undefined', toString: ƒ, Symbol(kIsNodeError): true}
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at new NodeError (/home/phil/Documents/GIT/gurglebot/lib/internal/errors.js:393:5)
at validateString (/home/phil/Documents/GIT/gurglebot/lib/internal/validators.js:161:11)
at parse (/home/phil/Documents/GIT/gurglebot/lib/path.js:1450:5)
at basename (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/util/Util.js:464:15)
at get spoiler [as spoiler] (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/structures/AttachmentBuilder.js:85:12)
at AttachmentBuilder.setSpoiler (/home/phil/Documents/GIT/gurglebot/node_modules/discord.js/src/structures/AttachmentBuilder.js:67:26)
at /home/phil/Documents/GIT/gurglebot/functions/ENGINE/contentWarning/COMPONENT/modal/repost.js:26:16
at /home/phil/Documents/GIT/gurglebot/node_modules/@discordjs/collection/dist/collection.cjs:174:14
at Function.from (<anonymous>)
at Collection.map (/home/phil/Documents/GIT/gurglebot/node_modules/@discordjs/collection/dist/collection.cjs:172:18) {code: 'ERR_INVALID_ARG_TYPE', stack: 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" …cordjs/collection/dist/collection.cjs:172:18)', message: 'The "path" argument must be of type string. Received undefined', toString: ƒ, Symbol(kIsNodeError): true}
17 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
MrMythical
MrMythical3y ago
Can you show your code
Phil
PhilOP3y ago
was about to
const files = message.attachments.map((file) => {
const attachment = new AttachmentBuilder(file.url);
attachment.setSpoiler(true);
return attachment;
});
const files = message.attachments.map((file) => {
const attachment = new AttachmentBuilder(file.url);
attachment.setSpoiler(true);
return attachment;
});
this is simplefied, because i was testing around alot trying to find the issue when i removed setSpoiler line, it worked fine
[phil@philtower gurglebot]$ node -v && npm -v
v18.9.0
8.19.1
[phil@philtower gurglebot]$ npm list discord.js
[email protected] /home/phil/Documents/GIT/gurglebot
[phil@philtower gurglebot]$ node -v && npm -v
v18.9.0
8.19.1
[phil@philtower gurglebot]$ npm list discord.js
[email protected] /home/phil/Documents/GIT/gurglebot
MrMythical
MrMythical3y ago
Try setting AttachmentBuilder name
Phil
PhilOP3y ago
yea... that might be it hold on yea thats it.. it also now makes sense, why ti was reporting about a string tho now.. not sure if this is related to it. it wont show a preview anymore i did have a woraround that i just added "SPOILER_" infront of the filename
MrMythical
MrMythical3y ago
What is the filename
Phil
PhilOP3y ago
left own solution (already comited) and right is the own that doesnt show a picture preview
Phil
PhilOP3y ago
Phil
PhilOP3y ago
do not question my nickname buuut it might be because of linux... i had it a a few time that this happend.. but on this . it is consistant
souji
souji3y ago
the SPOILER_ prefix in the image is how discord specifies if a thing should be a spoiler image, so that seems not really related to discord.js doing sth wrong
Phil
PhilOP3y ago
yea
souji
souji3y ago
does the image properly embed, if you do not spoiler it?
Phil
PhilOP3y ago
tho when i do it manually with
const files = message.attachments.map((file) => ({ attachment: file.url, name: `SPOILER_${file.name}` }));
const files = message.attachments.map((file) => ({ attachment: file.url, name: `SPOILER_${file.name}` }));
it works fine it.. nvm its pobably linux doing a funni on me because i just tested it again and it worked fine
souji
souji3y ago
can you provide a minimal sample, please? there's quite a bit of interdependency happening here
Phil
PhilOP3y ago
define minimal sample, please
Almeida
Almeida3y ago
Stack Overflow
How to create a Minimal, Reproducible Example - Help Center
Stack Overflow | The World’s Largest Online Community for Developers
Phil
PhilOP3y ago
unfortunately i dont quite understand what cant be understood. the bug happens, when no name is set for the file. aka i currently dont have the time to mess with this issue. if a workaround has been found

Did you find this page helpful?