File Upload
type: 19
Modals
Preview modal.json
MODAL_SUBMIT data (trimmed)
The File Upload lets users upload files (up to 10) from a modal. It goes inside a Label.
Send a screenshot
Error screenshots*
Upload up to 3 images.
Drag files or click to upload
{ "type": 9, "data": { "custom_id": "send_screenshot", "title": "Send a screenshot", "components": [ { "type": 18, "label": "Error screenshots", "description": "Upload up to 3 images.", "component": { "type": 19, "custom_id": "screenshots", "min_values": 1, "max_values": 3, "file_types": [ "image" ] } } ] }}Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
type |
integer | required Always 19. |
id |
integer | optional Unique identifier. |
custom_id |
string | required 1-100 characters. |
min_values |
integer | optional Minimum files (0-10). Defaults to 1. |
max_values |
integer | optional Maximum files (max 10). Defaults to 1. |
required |
boolean | optional Defaults to true. |
file_types |
array of strings | optional Up to 10 filters: "image", "video", "audio" or extensions like ".pdf". |
What your bot receives
Section titled “What your bot receives”values contains the attachment IDs, and the full data (URL, name, size…) is in resolved.attachments:
{ "custom_id": "send_screenshot", "components": [ { "type": 18, "id": 1, "component": { "type": 19, "id": 2, "custom_id": "screenshots", "values": ["111111111111111111"] } } ], "resolved": { "attachments": { "111111111111111111": { "id": "111111111111111111", "filename": "error.png", "size": 48213, "url": "https://cdn.discordapp.com/ephemeral-attachments/...", "content_type": "image/png" } } }}Respond to the interaction with the JSON above.
await interaction.showModal({ custom_id: 'send_screenshot', title: 'Send a screenshot', components: [ { type: 18, label: 'Error screenshots', component: { type: 19, custom_id: 'screenshots', min_values: 1, max_values: 3 }, }, ],});
// When the modal is submittedif (interaction.isModalSubmit() && interaction.customId === 'send_screenshot') { const files = interaction.fields.getUploadedFiles('screenshots'); // Collection<id, Attachment> const urls = files.map((file) => file.url);}class SendScreenshot(discord.ui.Modal, title="Send a screenshot"): screenshots = discord.ui.Label( text="Error screenshots", description="Upload up to 3 images.", component=discord.ui.FileUpload(min_values=1, max_values=3), )
async def on_submit(self, interaction: discord.Interaction): files = self.screenshots.component.values # list of discord.Attachment names = ", ".join(a.filename for a in files) await interaction.response.send_message(f"Received: {names}", ephemeral=True)minFiles := 1discordgo.Label{ Label: "Error screenshots", Description: "Upload up to 3 images.", Component: discordgo.FileUpload{ CustomID: "screenshots", MinValues: &minFiles, MaxValues: 3, },}
// On MODAL_SUBMIT, the *discordgo.FileUpload carries the IDs in Values.// The full data for each file is in the interaction's data.resolved.attachments.