Skip to content

feat(components,commands): support restricting allowed file types in FileUpload modal components and slash command attachment options#1550

Merged
shiftinv merged 11 commits into
masterfrom
feat/file-upload-types
Jul 9, 2026
Merged

feat(components,commands): support restricting allowed file types in FileUpload modal components and slash command attachment options#1550
shiftinv merged 11 commits into
masterfrom
feat/file-upload-types

Conversation

@shiftinv

@shiftinv shiftinv commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Note

This is in private testing at the moment, and will be made available to everyone within the next couple weeks.

This adds a file_types parameter/field to components.FileUpload and ui.FileUpload, as well as Option and Param/ParamInfo for slash commands.

Valid values are the predefined image/video/audio groups and arbitrary extensions such as .pdf, or any combination thereof (up to 10, where each one can be up to 16 chars).

IMAGE_EXTENSIONS = ('.png', '.gif', '.jpg', '.jpeg', '.jfif', '.webp', '.avif')
VIDEO_EXTENSIONS = ('.mp4', '.mov', '.qt', '.webm')
AUDIO_EXTENSIONS = ('.mp3', '.m4a', '.wav', '.ogg', '.opus', '.flac')

(and, once again, we're at a point where a Sequence[str] that doesn't allow str would be great)

Modal FileUpload example

image

Checklist

  • If code changes were made, then they have been tested
    • I have updated the documentation to reflect the changes
    • I have formatted the code properly by running uv run nox -s lint
    • I have type-checked the code by running uv run nox -s pyright
  • This PR fixes an issue
  • This PR adds something new (e.g. new method or parameters)
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@shiftinv shiftinv added this to the disnake v2.13 milestone Jun 23, 2026
@shiftinv shiftinv added this to disnake Jun 23, 2026
@shiftinv shiftinv added t: enhancement New feature t: api support Support of Discord API features s: needs review Issue/PR is awaiting reviews labels Jun 23, 2026
@github-project-automation github-project-automation Bot moved this to Todo in disnake Jun 23, 2026
@read-the-docs-community

read-the-docs-community Bot commented Jun 23, 2026

Copy link
Copy Markdown

Documentation build overview

📚 disnake | 🛠️ Build #33478849 | 📁 Comparing a3263ba against latest (57e1005)

  🔍 Preview build  

51 files changed · ± 51 modified

± Modified

@shiftinv shiftinv changed the title feat: support restricting allowed file types in FileUpload modal components and slash command attachment options feat(components,commands): support restricting allowed file types in FileUpload modal components and slash command attachment options Jun 23, 2026
@Enegg

Enegg commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Could you clarify:

Valid values are the predefined image/video/audio groups

Are those pre-defined by discord, or are they library-supplied shorthands?

I'm assuming the former, since the PR doesn't seem to include any lib-specific mechanisms

@shiftinv

Copy link
Copy Markdown
Member Author

Are those pre-defined by discord, or are they library-supplied shorthands?

I'm assuming the former, since the PR doesn't seem to include any lib-specific mechanisms

Yup. The mappings are mentioned in the PR description (copied 1:1 from the announcement), I'm still kind of debating whether we should document them.

@Enegg

Enegg commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

I'm still kind of debating whether we should document them.

Hmm, what do you think of doing something like

file_types: list[str | Literal["image", "video", "audio"]] | None = None

So just by inspecting the signature you could see there are some magic values available
(docstring can stay file_types: :class:'list'[:class:'str'] | :data:'None' since it is explained below)

Pylance may even offer some autocompletion
image
Though it's not smart enough to do it for the list display
image

@shiftinv

Copy link
Copy Markdown
Member Author

So just by inspecting the signature you could see there are some magic values available

Hmm, good point, I'll add those again to at least have them show up in the signature.
I did try it originally, but also noticed the same behavior you saw, with pylance not suggesting these literal values in lists -- unfortunate :/

@shiftinv shiftinv merged commit 863033f into master Jul 9, 2026
34 checks passed
@shiftinv shiftinv deleted the feat/file-upload-types branch July 9, 2026 17:16
@github-project-automation github-project-automation Bot moved this from Todo to Done in disnake Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s: needs review Issue/PR is awaiting reviews t: api support Support of Discord API features t: enhancement New feature

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants