Repository navigation
feat(plugin-gateway): add AttachmentBuilder - #230
Conversation
Add discord.js's AttachmentBuilder (setFile, setName, setDescription, setSpoiler, setTitle, setDuration, setWaveform, toJSON, from) to build the files of a message, and Attachment#attachment as an alias of the URL of a received attachment.
|
Note This drawing shows
1 finding · reviewed 🟠 Copying a named payload drops its spoiler flag ·
|
There was a problem hiding this comment.
ℹ️ No critical issues — one small behavioral gap in
AttachmentBuilder.from.
Reviewed changes
Reviewed the full diff of the single commit, cross-checked against MessagePayload (resolveFile, attachmentPayload, resolveAttachments) and the Attachment base class.
AttachmentBuilder— discord.js v14-style builder with chainable setters,spoilergetter,toJSON()andfrom(), plus deferred spoiler handling when no name is set yet.Attachment#attachment— getter returningurl, soAttachmentBuilder.from(received)works.- Tests, type contracts, README, changeset — cover setters, spoiler handling,
from, and sending throughMessagePayload.
claude-sonnet-5-5 | 𝕏
AttachmentBuilder.from only carried a spoiler over when the source had no name, so a named payload with spoiler: true, or a received attachment with the IsSpoiler flag but no SPOILER_ prefix, was copied as a regular file. It now calls setSpoiler(), which handles both cases.
@wolfstar/plugin-api
@wolfstar/plugin-broker
@wolfstar/plugin-cache
@wolfstar/plugin-gateway
@wolfstar/plugin-i18next
@wolfstar/plugin-logger
@wolfstar/plugin-scheduled-tasks
@wolfstar/plugin-sharder
@wolfstar/plugin-subcommands-advanced
commit: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the incremental delta since the prior pullfrog review (0ae2455 → 2b29755).
AttachmentBuilder.fromkeeps the spoiler of named sources — it now callssetSpoiler()whenever the source is a spoiler, so a named payload or a receivedAttachmentwith theIsSpoilerflag gets theSPOILER_prefix, and an unnamed one keeps the pending flag. This resolves the prior inline finding.- New test for
fromwith spoilers — covers named, unnamed, flagged receivedAttachmentand non-spoiler sources.
claude-sonnet-5-5 | 𝕏

🔗 Linked issue
N/A, no open issue for this.
🧭 Context
@wolfstar/plugin-gatewayalready sendsfilesand describes them inattachmentsthroughMessagePayload, and already has the receivedAttachment. What was missing is discord.js's way to build a file:AttachmentBuilder.MessagePayloadeven documents "an attachment builder" as an acceptedfilesentry, but there was none to use.📚 Description
Adds
AttachmentBuilderwith discord.js v14's API, so code ported from discord.js keeps working:new AttachmentBuilder(file, { name, description }), the chainablesetFile,setName,setDescriptionandsetSpoiler, thespoilergetter,toJSON()andAttachmentBuilder.from(other). It also hassetTitle,setDurationandsetWaveform, becauseAttachmentPayloadalready supports them (voice messages).setSpoileradds or removes theSPOILER_prefix of the name, as in discord.js. When the name is not set yet (it is inferred from a path or URL when sending), the builder remembers the flag andMessagePayloadprefixes the inferred name.Attachment#attachmentnow returns the URL of a received attachment, as in discord.js. That makesAttachmentBuilder.from(message.attachments.first())work to resend a file.I did not change the rest of
Attachment:name,spoiler,duration,flagsandcreatedAtwere already there. I could not check what discord.js v15 keeps of this API, so this follows v14.Key changes
filesAttachmentBuilder, exported from@wolfstar/plugin-gatewayAttachment#attachmentmissingurlsrc/structures/messages/AttachmentBuilder.ts(new), exported frommessages/index.ts.src/structures/messages/Attachment.ts:attachmentgetter.tests/attachment-builder.test.ts(new): setters, spoiler handling with and without a name,from(builder, payload, received attachment), and sending throughMessagePayload.tests/types/contracts.ts: type contract for the builder andAttachment#attachment.minorchangeset for@wolfstar/plugin-gateway.Type of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.