feat: more attachment and embed fields#11480
feat: more attachment and embed fields#11480kshitijanurag wants to merge 1 commit intodiscordjs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
📝 WalkthroughWalkthroughThis 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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🔵 TrivialInconsistent JSDoc: constructor param description not updated.
This PR updated the constructor JSDoc in
EmbedAuthor,EmbedFooter,EmbedField, andEmbedProviderfrom "connection" to the specific component name, butEmbed.tsstill 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
📒 Files selected for processing (18)
packages/discord.js/src/structures/Attachment.jspackages/discord.js/src/structures/Embed.jspackages/discord.js/src/util/EmbedFlagsBitField.jspackages/discord.js/src/util/EmbedMediaFlagsBitField.jspackages/discord.js/typings/index.d.tspackages/structures/src/bitfields/EmbedFlagsBitField.tspackages/structures/src/bitfields/EmbedMediaFlagsBitField.tspackages/structures/src/bitfields/UnfurledMediaItemFlagsBitField.tspackages/structures/src/messages/Attachment.tspackages/structures/src/messages/components/UnfurledMediaItem.tspackages/structures/src/messages/embeds/Embed.tspackages/structures/src/messages/embeds/EmbedAuthor.tspackages/structures/src/messages/embeds/EmbedField.tspackages/structures/src/messages/embeds/EmbedFooter.tspackages/structures/src/messages/embeds/EmbedImage.tspackages/structures/src/messages/embeds/EmbedProvider.tspackages/structures/src/messages/embeds/EmbedThumbnail.tspackages/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.jspackages/discord.js/src/util/EmbedMediaFlagsBitField.jspackages/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.jspackages/discord.js/src/util/EmbedMediaFlagsBitField.jspackages/discord.js/src/structures/Attachment.jspackages/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.tspackages/structures/src/bitfields/EmbedMediaFlagsBitField.tspackages/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 constructingUnfurledMediaItemFlagsBitField, and correctly returnsnullwhen absent.
59-71: New media metadata getters and doc updates look consistent.
placeholder/placeholderVersionpassthroughs 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
APIEmbedThumbnailtoAPIEmbedImagealigns 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 inEmbedImage.tsandEmbedVideo.ts. The conditionalflagsgetter withisFieldSetcheck 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
flagsgetter follows the established pattern usingisFieldSetfor 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, andflagsfollow the established patterns. Theflagsgetter correctly usesisFieldSetto 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
EmbedFlagsBitFieldwith a fallback to0when 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 conditionalflagsbitfield follow the established patterns correctly.packages/structures/src/messages/Attachment.ts (1)
112-124: LGTM on placeholder getters.The
placeholderandplaceholderVersiongetters correctly read from the raw data and follow the established pattern.
Add more attachment and embeds fields
Discord API Docs reference:
Depends on: