Skip to content

Commit e20f53a

Browse files
Add support for gif stickers (#2377)
1 parent 993c877 commit e20f53a

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/main/java/net/dv8tion/jda/api/entities/Guild.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4582,7 +4582,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
45824582
* @param description
45834583
* The sticker description (2-100 characters, or empty)
45844584
* @param file
4585-
* The sticker file containing the asset (png/apng/lottie) with valid file extension (png or json)
4585+
* The sticker file containing the asset (png/apng/gif/lottie) with valid file extension (png, gif, or json)
45864586
* @param tags
45874587
* The tags to use for auto-suggestions (Up to 200 characters in total)
45884588
*
@@ -4592,7 +4592,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
45924592
* <ul>
45934593
* <li>If the name is not between 2 and 30 characters long</li>
45944594
* <li>If the description is more than 100 characters long or exactly 1 character long</li>
4595-
* <li>If the asset file is null or of an invalid format (must be PNG or LOTTIE)</li>
4595+
* <li>If the asset file is null or of an invalid format (must be PNG, GIF, or LOTTIE)</li>
45964596
* <li>If anything is {@code null}</li>
45974597
* </ul>
45984598
*
@@ -4618,7 +4618,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
46184618
* @param description
46194619
* The sticker description (2-100 characters, or empty)
46204620
* @param file
4621-
* The sticker file containing the asset (png/apng/lottie) with valid file extension (png or json)
4621+
* The sticker file containing the asset (png/apng/gif/lottie) with valid file extension (png, gif, or json)
46224622
* @param tag
46234623
* The sticker tag used for suggestions (emoji or tag words)
46244624
* @param tags
@@ -4630,7 +4630,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
46304630
* <ul>
46314631
* <li>If the name is not between 2 and 30 characters long</li>
46324632
* <li>If the description is more than 100 characters long or exactly 1 character long</li>
4633-
* <li>If the asset file is null or of an invalid format (must be PNG or LOTTIE)</li>
4633+
* <li>If the asset file is null or of an invalid format (must be PNG, GIF, or LOTTIE)</li>
46344634
* <li>If anything is {@code null}</li>
46354635
* </ul>
46364636
*

src/main/java/net/dv8tion/jda/api/entities/sticker/Sticker.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ enum StickerFormat
145145
* @see <a href="https://airbnb.io/lottie/">Lottie website</a>
146146
*/
147147
LOTTIE(3, "json"),
148+
/**
149+
* The GIF format.
150+
*/
151+
GIF(4, "gif"),
148152
/**
149153
* Represents any unknown or unsupported format types.
150154
*/

src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ public AuditableRestAction<GuildSticker> createSticker(@Nonnull String name, @No
17851785

17861786
// Extract file extension and map to media type
17871787
int index = file.getName().lastIndexOf('.');
1788-
Checks.check(index > -1, "Filename for sticker is missing file extension. Provided: '" + file.getName() + "'. Must be PNG or JSON.");
1788+
Checks.check(index > -1, "Filename for sticker is missing file extension. Provided: '" + file.getName() + "'. Must be PNG, GIF, or JSON.");
17891789

17901790
// Convert file extension to media-type
17911791
String extension = file.getName().substring(index + 1).toLowerCase(Locale.ROOT);
@@ -1796,11 +1796,14 @@ public AuditableRestAction<GuildSticker> createSticker(@Nonnull String name, @No
17961796
case "png":
17971797
mediaType = Requester.MEDIA_TYPE_PNG;
17981798
break;
1799+
case "gif":
1800+
mediaType = Requester.MEDIA_TYPE_GIF;
1801+
break;
17991802
case "json":
18001803
mediaType = Requester.MEDIA_TYPE_JSON;
18011804
break;
18021805
default:
1803-
throw new IllegalArgumentException("Unsupported file extension: '." + extension + "', must be PNG or JSON.");
1806+
throw new IllegalArgumentException("Unsupported file extension: '." + extension + "', must be PNG, GIF, or JSON.");
18041807
}
18051808

18061809
// Add sticker metadata as form parts (because payload_json is broken)

src/main/java/net/dv8tion/jda/internal/requests/Requester.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class Requester
5555
public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
5656
public static final MediaType MEDIA_TYPE_OCTET = MediaType.parse("application/octet-stream; charset=utf-8");
5757
public static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
58+
public static final MediaType MEDIA_TYPE_GIF = MediaType.parse("image/gif");
5859

5960
protected final JDAImpl api;
6061
protected final AuthorizationConfig authConfig;

0 commit comments

Comments
 (0)