Skip to content

Conversation

@didinele
Copy link
Member

@didinele didinele commented Nov 17, 2025

Depends on #11248

Closes #11273

@vercel vercel bot temporarily deployed to Preview – discord-js November 17, 2025 07:41 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 17, 2025 07:41 Inactive
@vercel
Copy link

vercel bot commented Nov 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
discord-js Skipped Skipped Nov 20, 2025 1:23pm
discord-js-guide Skipped Skipped Nov 20, 2025 1:23pm

@didinele didinele changed the title feat(builders): multipart form data output support refactor: new AttachmentBuilder in mainlib Nov 17, 2025
@didinele didinele changed the title refactor: new AttachmentBuilder in mainlib refactor: new MessageBuilder in mainlib Nov 17, 2025
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 17, 2025 09:39 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js November 17, 2025 09:39 Inactive
@didinele
Copy link
Member Author

Ready for review, but blocked until the other PR is merged.

@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.97%. Comparing base (68bb8af) to head (e6aef1e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11278   +/-   ##
=======================================
  Coverage   44.97%   44.97%           
=======================================
  Files         317      317           
  Lines       18222    18222           
  Branches     1817     1817           
=======================================
  Hits         8196     8196           
  Misses      10013    10013           
  Partials       13       13           
Flag Coverage Δ
builders 81.15% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@didinele didinele force-pushed the refactor/mainlib-for-builders-updates branch from 5fc03b1 to 2207fa3 Compare November 20, 2025 08:42
@vercel vercel bot temporarily deployed to Preview – discord-js November 20, 2025 08:42 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 20, 2025 08:42 Inactive
@didinele didinele marked this pull request as ready for review November 20, 2025 08:43
@didinele didinele requested a review from a team as a code owner November 20, 2025 08:43
@vercel vercel bot temporarily deployed to Preview – discord-js November 20, 2025 10:52 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 20, 2025 10:52 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js November 20, 2025 11:00 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 20, 2025 11:00 Inactive
@didinele didinele changed the title feat: new MessageBuilder in discord.js refactor: remove AttachmentBuilder and support new file body encodables Nov 20, 2025
@didinele didinele changed the title refactor: remove AttachmentBuilder and support new file body encodables refactor!: remove AttachmentBuilder and support new file body encodables Nov 20, 2025
@Jiralite Jiralite dismissed their stale review November 20, 2025 11:09

Resolved.

@vercel vercel bot temporarily deployed to Preview – discord-js November 20, 2025 11:14 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 20, 2025 11:14 Inactive
@didinele didinele requested a review from Jiralite November 20, 2025 12:53
@didinele didinele requested a review from a team as a code owner November 20, 2025 12:53
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 20, 2025 12:53 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js November 20, 2025 12:53 Inactive
Co-authored-by: Jiralite <[email protected]>
@vercel vercel bot temporarily deployed to Preview – discord-js-guide November 20, 2025 13:22 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js November 20, 2025 13:23 Inactive
@didinele didinele requested a review from Jiralite November 20, 2025 13:23
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
* (see {@link https://discord.com/developers/docs/resources/message#allowed-mentions-object here} for more details)
* @property {Array<(AttachmentBuilder|Attachment|AttachmentPayload|BufferResolvable)>} [files]
* @property {Array<(Attachment|AttachmentPayload|BufferResolvable)>} [files]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if there was still a way to pass an AttachmentBuilder into here, albeit not sure what type would make sense to put for that here.

Another helper type like RawFileEncodable which extends JSONEncodable with the additional getRawFile() method? Seems clunky but 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue I have with this is that AttachmentBuilder includes data tied to.. well, the attachments array.

What do we do when the user sets that data and they also provide attachments manually?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same we did before:

const attachments = this.options.files?.map((file, index) => ({
id: index.toString(),
description: file.description,
title: file.title,
waveform: file.waveform,
duration_secs: file.duration,
}));
if (Array.isArray(this.options.attachments)) {
this.options.attachments.push(...(attachments ?? []));
} else {
this.options.attachments = attachments;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is absolutely awful in terms of library behavior. That snippet effectively means that if you pass both files and attachments at the same time, it's a guaranteed API error, unless it's a message edit and the elements the user passed to the attachments array specifically refer to existing attachments.

In essence, this renders the attachments field as edit-only, we're just completely taking over it with this behavior, largely hiding how the API payload works too (which I am not fond of at all, no matter how rich the the abstraction).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's what AttachmentBuilder does too... it hides the same things the same way.

Copy link
Member Author

@didinele didinele Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This isn't about hiding things, it's allowing the user to easily pass garbage. AttachmentBuilder on its own is fundamentally different from what you want, it removes your granular control of the files/attachments fields, it ties them together completely. There is no way when using it to get non-sense miss-matched arrays. All the more so when you use MessageBuilder

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circling back on this, the only way I'd accept it is making it a union type that forbids files if attachments is AttachmentBuilder[], I'm not compromising otherwise

Copy link
Member

@Qjuh Qjuh Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thing is that all the other types allowed for files here will also fill the attachments. So if anything it would make sense to completely disallow attachments in create Message options.

And you got it backwards: it's an accepted type for the files property and will disallow the attachments property.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'm okay with designing the API that way, but we do also have to acknowledge the complexity it adds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Review in Progress

Development

Successfully merging this pull request may close these issues.

Remove AttachmentBuilder from discord.js

5 participants