File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @embedly/builder " : patch
3+ ---
4+
5+ cap media gallery items at Discord's 10-item limit
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ export interface EmbedFlags {
7777 [ EmbedFlagNames . LinkStyle ] : "control" | "inline" | "none" ;
7878}
7979
80+ const MAX_GALLERY_ITEMS = 10 ;
81+
8082export 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 > ) {
You can’t perform that action at this time.
0 commit comments