Skip to content

feat: more attachment and embed fields#11480

Open
kshitijanurag wants to merge 1 commit intodiscordjs:mainfrom
kshitijanurag:patch-2
Open

feat: more attachment and embed fields#11480
kshitijanurag wants to merge 1 commit intodiscordjs:mainfrom
kshitijanurag:patch-2

Conversation

@kshitijanurag
Copy link
Copy Markdown

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

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

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
discord-js Skipped Skipped Apr 4, 2026 1:18pm
discord-js-guide Skipped Skipped Apr 4, 2026 1:18pm

Request Review

@vercel vercel bot temporarily deployed to Preview – discord-js-guide April 4, 2026 12:22 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js April 4, 2026 12:22 Inactive
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

This PR extends Discord.js structures with comprehensive support for embed and attachment media metadata. New BitField classes handle embed and media flags, Attachment gains placeholder and clip-related properties, and Embed media elements (images, videos, thumbnails) are enriched with content type, description, and flag metadata. JSDoc corrections clarify component purposes across embed classes.

Changes

Cohort / File(s) Summary
Attachment Properties
packages/discord.js/src/structures/Attachment.js, packages/structures/src/messages/Attachment.ts, packages/discord.js/typings/index.d.ts
Added nullable placeholder and placeholderVersion properties, plus clip-related fields (clipParticipants, clipCreatedAt, clipApplication). Attachment.ts implements optimizeData() to parse clip_created_at timestamps and manages data template for clip fields.
Embed Flags BitFields
packages/discord.js/src/util/EmbedFlagsBitField.js, packages/discord.js/src/util/EmbedMediaFlagsBitField.js, packages/structures/src/bitfields/EmbedFlagsBitField.ts, packages/structures/src/bitfields/EmbedMediaFlagsBitField.ts, packages/structures/src/bitfields/UnfurledMediaItemFlagsBitField.ts
Introduced three new BitField subclasses to handle embed-level flags, embed media (image/video/thumbnail) flags, and unfurled media item flags with appropriate static Flags mappings and toJSON() serialization.
Embed Class Updates
packages/discord.js/src/structures/Embed.js, packages/structures/src/messages/embeds/Embed.ts, packages/discord.js/typings/index.d.ts
Added flags getter returning frozen EmbedFlagsBitField, extended EmbedAssetData typedef with contentType, placeholder, placeholderVersion, description, and media flags. Updated Embed#equals() to compare embed flags.
Embed Media Classes
packages/structures/src/messages/embeds/EmbedImage.ts, packages/structures/src/messages/embeds/EmbedVideo.ts, packages/structures/src/messages/embeds/EmbedThumbnail.ts
Extended with getters for contentType, placeholder, placeholderVersion, description, and conditional flags (returning `EmbedMediaFlagsBitField
Component Updates
packages/structures/src/messages/components/UnfurledMediaItem.ts
Added flags getter returning `UnfurledMediaItemFlagsBitField
Documentation Corrections
packages/structures/src/messages/embeds/EmbedAuthor.ts, packages/structures/src/messages/embeds/EmbedField.ts, packages/structures/src/messages/embeds/EmbedFooter.ts, packages/structures/src/messages/embeds/EmbedProvider.ts
Clarified JSDoc @param data descriptions in constructors to reference specific component types (e.g., "embed author" instead of generic "connection").

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: more attachment and embed fields' directly describes the main objective of the changeset, which adds new attachment and embed-related fields across multiple files.
Description check ✅ Passed The description clearly relates to the changeset by specifying the addition of attachment and embed fields, with supporting API documentation references.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/structures/src/messages/embeds/Embed.ts (1)

25-27: 🧹 Nitpick | 🔵 Trivial

Inconsistent JSDoc: constructor param description not updated.

This PR updated the constructor JSDoc in EmbedAuthor, EmbedFooter, EmbedField, and EmbedProvider from "connection" to the specific component name, but Embed.ts still has the generic "connection" wording. Consider updating for consistency.

📝 Suggested fix
 	/**
-	 * `@param` data - The raw data received from the API for the connection
+	 * `@param` data - The raw data received from the API for the embed
 	 */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/structures/src/messages/embeds/Embed.ts` around lines 25 - 27,
Update the constructor JSDoc in the Embed class: replace the generic "@param
data - The raw data received from the API for the connection" with a specific
description such as "@param data - The raw embed data received from the API" so
it matches the updates made in EmbedAuthor, EmbedFooter, EmbedField, and
EmbedProvider; locate the Embed constructor/JSDoc in Embed.ts and edit the param
description accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/discord.js/src/structures/Attachment.js`:
- Around line 187-196: The TypeScript type for the Attachment property
clipParticipants must be updated to match the implementation and JSDoc; change
its declaration in the Attachment class (symbol: clipParticipants) from readonly
APIUser[] to readonly APIUser[] | null so it can be null like
title/description/clipApplication, and ensure any exported types or interfaces
referencing clipParticipants are updated to readonly APIUser[] | null as well.
- Around line 209-218: The Attachment class defines and assigns
this.clipApplication but the TypeScript typings declare application:
APIApplication | null, causing a name mismatch; rename the property to
this.application everywhere in the Attachment implementation (replace
occurrences of clipApplication in the conditional, the assignment
this.clipApplication = data.clip_application, and the fallback
this.clipApplication ??= null) and update the JSDoc block to reference
application and the APIApplication type so the runtime property name matches the
typings (also search the Attachment class for any other references to
clipApplication and replace them with application).

In `@packages/discord.js/src/structures/Embed.js`:
- Around line 274-276: The equality check incorrectly assumes other.flags has a
.bitfield; update the comparison in the Embed equality block (where this.image,
this.thumbnail, this.flags are compared) to normalize flags to a numeric value
before comparing: extract otherFlags as typeof other.flags === 'number' ?
other.flags : other.flags?.bitfield (or 0 if undefined) and compare
this.flags?.bitfield to that numeric otherFlags so both sides are numbers and
the comparison works for APIEmbed (raw number) and EmbedFlagsBitField instances.

In `@packages/discord.js/src/util/EmbedMediaFlagsBitField.js`:
- Around line 13-21: The JS EmbedMediaFlagsBitField class is missing a toJSON
override present in the TS version; add a toJSON(asNumber) method to
EmbedMediaFlagsBitField that returns super.toJSON(true) so the flags are always
serialized as numeric values—modify the EmbedMediaFlagsBitField class to include
this toJSON override referencing the existing BitField superclass.

In `@packages/discord.js/typings/index.d.ts`:
- Around line 817-825: The EmbedAssetData typings are incorrect: make
description optional (it can be undefined at runtime) and add a flags field to
match the getter in src/structures/Embed.js; define a new
EmbedMediaFlagsBitField type (or alias) alongside EmbedFlagsBitField and use it
as the type for flags on EmbedAssetData, or alternatively split into separate
input/output media types (e.g., EmbedAssetInput vs EmbedAssetOutput) and ensure
EmbedData uses the correct variant; update references to EmbedAssetData and
EmbedData so their shapes align with the runtime forwarding in Embed.js.

In `@packages/structures/src/bitfields/EmbedFlagsBitField.ts`:
- Around line 1-16: Add an export for the new EmbedFlagsBitField class to the
bitfields barrel so external consumers can import it via the package barrel;
specifically update the bitfields index barrel (the file that re-exports
bitfield classes) to include an export for EmbedFlagsBitField by adding a line
that exports the symbol EmbedFlagsBitField (e.g., export * from
'./EmbedFlagsBitField.js') so the class (EmbedFlagsBitField) is publicly
available alongside the other bitfield exports.

In `@packages/structures/src/messages/Attachment.ts`:
- Around line 166-168: The clipCreatedAt getter currently reads the stripped raw
field this[kData].clip_created_at which will be undefined; change the getter to
return the optimized timestamp stored in this[kClipCreatedAt] (the value set by
optimizeData/DataTemplate) following the same pattern used in Message.ts so
clipCreatedAt returns the parsed timestamp instead of the stripped raw value.
- Around line 16-21: Add and export the missing symbol kClipCreatedAt from the
symbols module (define Symbol.for('djs.structures.clipCreatedAt') and export it
alongside the other symbols) and then import that exported kClipCreatedAt into
Attachment (where the protected [kClipCreatedAt] field is used) so the symbol
reference resolves at runtime; update the symbols export and the Attachment
import statements to use the new kClipCreatedAt identifier.

---

Outside diff comments:
In `@packages/structures/src/messages/embeds/Embed.ts`:
- Around line 25-27: Update the constructor JSDoc in the Embed class: replace
the generic "@param data - The raw data received from the API for the
connection" with a specific description such as "@param data - The raw embed
data received from the API" so it matches the updates made in EmbedAuthor,
EmbedFooter, EmbedField, and EmbedProvider; locate the Embed constructor/JSDoc
in Embed.ts and edit the param description accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 756f3c2c-21c7-45a0-9852-037f98ba4652

📥 Commits

Reviewing files that changed from the base of the PR and between 1f9affd and ceca211.

📒 Files selected for processing (18)
  • packages/discord.js/src/structures/Attachment.js
  • packages/discord.js/src/structures/Embed.js
  • packages/discord.js/src/util/EmbedFlagsBitField.js
  • packages/discord.js/src/util/EmbedMediaFlagsBitField.js
  • packages/discord.js/typings/index.d.ts
  • packages/structures/src/bitfields/EmbedFlagsBitField.ts
  • packages/structures/src/bitfields/EmbedMediaFlagsBitField.ts
  • packages/structures/src/bitfields/UnfurledMediaItemFlagsBitField.ts
  • packages/structures/src/messages/Attachment.ts
  • packages/structures/src/messages/components/UnfurledMediaItem.ts
  • packages/structures/src/messages/embeds/Embed.ts
  • packages/structures/src/messages/embeds/EmbedAuthor.ts
  • packages/structures/src/messages/embeds/EmbedField.ts
  • packages/structures/src/messages/embeds/EmbedFooter.ts
  • packages/structures/src/messages/embeds/EmbedImage.ts
  • packages/structures/src/messages/embeds/EmbedProvider.ts
  • packages/structures/src/messages/embeds/EmbedThumbnail.ts
  • packages/structures/src/messages/embeds/EmbedVideo.ts
📜 Review details
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: Qjuh
Repo: discordjs/discord.js PR: 11423
File: packages/discord.js/src/structures/MessagePayload.js:193-206
Timestamp: 2026-02-16T18:45:40.408Z
Learning: In discord.js MessagePayload.js, when mapping files to attachments, custom ids set via AttachmentBuilder.setId() should override the index-based id. The spread operator should come after the explicit id assignment to allow toJSON() values to take precedence.
📚 Learning: 2026-01-24T21:41:23.189Z
Learnt from: Qjuh
Repo: discordjs/discord.js PR: 11393
File: packages/structures/src/bitfields/ApplicationFlagsBitField.ts:13-15
Timestamp: 2026-01-24T21:41:23.189Z
Learning: In discord.js BitField classes, the toJSON(asNumber?: boolean) method returns a numeric value when asNumber is true, and returns a string representation when asNumber is false or undefined. To preserve numeric flags, use super.toJSON(true).

Applied to files:

  • packages/discord.js/src/util/EmbedFlagsBitField.js
  • packages/discord.js/src/util/EmbedMediaFlagsBitField.js
  • packages/discord.js/typings/index.d.ts
📚 Learning: 2026-03-30T11:04:39.419Z
Learnt from: almeidx
Repo: discordjs/discord.js PR: 11471
File: packages/discord.js/src/util/Util.js:83-86
Timestamp: 2026-03-30T11:04:39.419Z
Learning: For the discord.js and rest packages, follow the existing convention for constructing request URLs: use the `api` base URL and `version` string via raw interpolation (e.g., `${api}/v${version}${route}`) without adding normalization such as trimming trailing slashes on `api` or stripping/adding/remapping a leading `v` on `version`. Do not recommend changing this behavior during code review unless the existing pattern in this repo is intentionally being replaced.

Applied to files:

  • packages/discord.js/src/util/EmbedFlagsBitField.js
  • packages/discord.js/src/util/EmbedMediaFlagsBitField.js
  • packages/discord.js/src/structures/Attachment.js
  • packages/discord.js/src/structures/Embed.js
📚 Learning: 2026-01-24T21:41:15.330Z
Learnt from: Qjuh
Repo: discordjs/discord.js PR: 11393
File: packages/structures/src/bitfields/ApplicationFlagsBitField.ts:13-15
Timestamp: 2026-01-24T21:41:15.330Z
Learning: For BitField classes, preserve numeric flags by using super.toJSON(true) when you need a numeric value. The toJSON(asNumber?: boolean) method returns a number when asNumber is true and a string otherwise, so always pass true to obtain a numeric representation for storage/comparison. This guidance applies to similar bitfield classes across the codebase (not just ApplicationFlagsBitField).

Applied to files:

  • packages/structures/src/bitfields/EmbedFlagsBitField.ts
  • packages/structures/src/bitfields/EmbedMediaFlagsBitField.ts
  • packages/structures/src/bitfields/UnfurledMediaItemFlagsBitField.ts
📚 Learning: 2026-04-04T01:34:02.472Z
Learnt from: AsadHumayun
Repo: discordjs/discord.js PR: 11407
File: packages/structures/src/skus/SKU.ts:78-84
Timestamp: 2026-04-04T01:34:02.472Z
Learning: In `packages/structures/src/skus/SKU.ts`, the getter is intentionally named `createdDate` (instead of `createdAt` used by other structures like Channel, Webhook, Sticker). This naming inconsistency is a planned change in the discord.js project and should not be flagged as an issue during reviews.

Applied to files:

  • packages/structures/src/messages/embeds/Embed.ts
📚 Learning: 2026-02-16T18:45:40.408Z
Learnt from: Qjuh
Repo: discordjs/discord.js PR: 11423
File: packages/discord.js/src/structures/MessagePayload.js:193-206
Timestamp: 2026-02-16T18:45:40.408Z
Learning: In discord.js MessagePayload.js, when mapping files to attachments, custom ids set via AttachmentBuilder.setId() should override the index-based id. The spread operator should come after the explicit id assignment to allow toJSON() values to take precedence.

Applied to files:

  • packages/discord.js/src/structures/Attachment.js
🔇 Additional comments (16)
packages/structures/src/bitfields/UnfurledMediaItemFlagsBitField.ts (2)

7-12: Bitfield class wiring is correct.

Line 7 and Line 11 correctly bind the typed wrapper to UnfurledMediaItemFlags, matching the existing BitField extension pattern.


13-15: Numeric JSON serialization is implemented correctly.

Line 14 uses super.toJSON(true), which preserves numeric flags for storage/comparison instead of stringifying.

Based on learnings: For BitField classes, preserve numeric flags by using super.toJSON(true) when you need a numeric value.

packages/structures/src/messages/components/UnfurledMediaItem.ts (2)

46-50: Flags getter safely handles optional API data.

Line 47’s isFieldSet(..., 'number') gate is the right guard before constructing UnfurledMediaItemFlagsBitField, and correctly returns null when absent.


59-71: New media metadata getters and doc updates look consistent.

placeholder/placeholderVersion passthroughs and the height/width/url doc clarifications are aligned with existing media structure patterns.

Also applies to: 81-89

packages/structures/src/messages/embeds/EmbedAuthor.ts (1)

12-14: LGTM!

The JSDoc correction improves documentation accuracy by specifying "embed author" instead of the generic "connection".

packages/structures/src/messages/embeds/EmbedFooter.ts (1)

12-14: LGTM!

Consistent JSDoc correction, matching the pattern applied to other embed component classes.

packages/structures/src/messages/embeds/EmbedField.ts (1)

12-14: LGTM!

JSDoc correction is consistent with the other embed component classes.

packages/structures/src/messages/embeds/EmbedProvider.ts (1)

15-17: LGTM!

JSDoc correction is consistent with the other embed component classes.

packages/structures/src/messages/embeds/EmbedThumbnail.ts (1)

1-85: LGTM!

The type switch from APIEmbedThumbnail to APIEmbedImage aligns with the Discord API where thumbnails share the same structure as images. The new media metadata getters (contentType, placeholder, placeholderVersion, description, flags) follow the same pattern used in EmbedImage.ts and EmbedVideo.ts. The conditional flags getter with isFieldSet check correctly handles optional/nullable flag values.

packages/discord.js/src/util/EmbedFlagsBitField.js (1)

1-29: LGTM!

The implementation follows the established BitField pattern used by other flag classes in the discord.js package.

packages/structures/src/messages/embeds/Embed.ts (1)

67-72: LGTM!

The flags getter follows the established pattern using isFieldSet for null-safety before constructing the bitfield, consistent with other embed media classes.

packages/structures/src/bitfields/EmbedMediaFlagsBitField.ts (1)

1-16: LGTM!

Clean implementation following the established BitField pattern. The toJSON(true) override correctly preserves numeric flags for serialization. Based on learnings: "For BitField classes, preserve numeric flags by using super.toJSON(true) when you need a numeric value."

packages/structures/src/messages/embeds/EmbedImage.ts (1)

1-84: LGTM!

The new getters for contentType, placeholder, placeholderVersion, description, and flags follow the established patterns. The flags getter correctly uses isFieldSet to guard against non-numeric values before constructing the bitfield.

packages/discord.js/src/structures/Embed.js (1)

82-90: LGTM on the flags getter.

The implementation correctly creates a frozen EmbedFlagsBitField with a fallback to 0 when flags are absent.

packages/structures/src/messages/embeds/EmbedVideo.ts (1)

1-85: LGTM!

Implementation is consistent with EmbedImage.ts. The new media metadata getters and conditional flags bitfield follow the established patterns correctly.

packages/structures/src/messages/Attachment.ts (1)

112-124: LGTM on placeholder getters.

The placeholder and placeholderVersion getters correctly read from the raw data and follow the established pattern.

@vercel vercel bot temporarily deployed to Preview – discord-js April 4, 2026 13:17 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide April 4, 2026 13:17 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js April 4, 2026 13:18 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide April 4, 2026 13:18 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant