Skip to content

Commit a260b61

Browse files
committed
🐛 fix(builder): cap media gallery items at Discord's 10-item limit
1 parent 1bf8976 commit a260b61

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

.changeset/wacky-teeth-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@embedly/builder": patch
3+
---
4+
5+
cap media gallery items at Discord's 10-item limit

packages/builder/src/Embed.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ export interface EmbedFlags {
7777
[EmbedFlagNames.LinkStyle]: "control" | "inline" | "none";
7878
}
7979

80+
const MAX_GALLERY_ITEMS = 10;
81+
8082
export class Embed implements EmbedData {
8183
public platform!: string;
8284
public color!: RGBTuple;
@@ -102,22 +104,30 @@ export class Embed implements EmbedData {
102104

103105
constructor(data: BaseEmbedData) {
104106
Object.assign(this, data);
107+
if (this.media) this.media = this.media.slice(0, MAX_GALLERY_ITEMS);
105108
}
106109

107110
public setDescription(text: string) {
108111
this.description = text;
109112
}
110113

111114
public setMedia(media: APIMediaGalleryItem[]) {
112-
this.media = media;
115+
this.media = media.slice(0, MAX_GALLERY_ITEMS);
113116
}
114117

115118
public setQuote(quote: BaseEmbedDataWithoutPlatform) {
116-
this.quote = quote;
119+
this.quote = quote.media
120+
? { ...quote, media: quote.media.slice(0, MAX_GALLERY_ITEMS) }
121+
: quote;
117122
}
118123

119124
public setReplyingTo(replying_to: BaseEmbedDataWithoutPlatform) {
120-
this.replying_to = replying_to;
125+
this.replying_to = replying_to.media
126+
? {
127+
...replying_to,
128+
media: replying_to.media.slice(0, MAX_GALLERY_ITEMS)
129+
}
130+
: replying_to;
121131
}
122132

123133
static getDiscordEmbed(embed: Embed, flags?: Partial<EmbedFlags>) {

0 commit comments

Comments
 (0)