feat: use byte sniffing - #477
Open
Droid00000 wants to merge 1 commit into
Open
Conversation
Droid00000
force-pushed
the
feat/magic-byte-sniffing
branch
from
July 25, 2026 06:10
4b2fe2e to
f2be16d
Compare
Droid00000
force-pushed
the
feat/magic-byte-sniffing
branch
from
July 25, 2026 06:11
132e841 to
0984abd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I understand that this is kinda out of the blue, and that this makes the code slightly more complex/approachable since you're dealing with file signatures and the like, but i have a kinda decent reason for wanting to change this
Unfortunately, if we ever want to support stickers (specifically allowing them to be uploaded to servers), we need to provide the exact content type of the sticker file. Unlike every-other endpoint that accepts file uploads, the sticker endpoint is strict and rejects
application/octet-streamor a content type that doesn't match the contents of a file.If you provide something like a
TempfileorStringIOto something likeServer#create_emojiit's currently always fallback to aimage/jpegcontent type. While this is okay right now because Discord basically ignores the content-type your provide in the base64 string, they could decide to make it strict at anytime (like stickers). You could technically do something like below, to provide the content type, I think it's pretty janky to expect people to be defining singleton methods:If we ever decide to ditch
rest-client, we won't be able to use themime-typesgem (unless we want to make it an explicit dependency) since it's a transitive dependency fromrest-client.All of the file types that Discord supports are well-documented and easy to find: https://en.wikipedia.org/wiki/List_of_file_signatures
Added
Discordrb.sniff_mime_type(thanks discord.py)Fixed
I snuck in the doc fixes related to the component builder not being documented on a few interaction methods.