Skip to content

Conversation

plun1331
Copy link
Member

@plun1331 plun1331 commented Sep 18, 2025

Summary

first
also bug fixes
currently locked to private beta, cannot be used publicly yet

this basically is just a duplicate of InputText with inspiration taken from Select for implementation

Information

  • 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, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@pycord-app
Copy link

pycord-app bot commented Sep 18, 2025

Thanks for opening this pull request!
Please make sure you have read the Contributing Guidelines and Code of Conduct.

This pull request can be checked-out with:

git fetch origin pull/2938/head:pr-2938
git checkout pr-2938

This pull request can be installed with:

pip install git+https://github.com/Pycord-Development/pycord@refs/pull/2938/head

@plun1331 plun1331 marked this pull request as ready for review September 18, 2025 06:31
@plun1331 plun1331 requested review from a team as code owners September 18, 2025 06:31
@plun1331
Copy link
Member Author

my test code for those who are able to test:

import discord
from discord import Interaction


class Modal(discord.ui.Modal):
    def __init__(self):
        super().__init__(title="Test Modal")
        self.add_item(discord.ui.InputText(required=False, label="Test", row=1))
        self.add_item(discord.ui.FileUpload(label="Upload Files", required=False, min_values=2, max_values=5, row=2))
        self.add_item(discord.ui.InputText(required=False, label="Test"))

    async def callback(self, interaction: Interaction):
        await interaction.response.defer(ephemeral=True, invisible=False)
        # reupload all attachments as files
        attachments = self.children[1].values
        print(attachments)
        files = [await attachment.to_file() for attachment in attachments]
        await interaction.followup.send("Here are your files:", files=files, ephemeral=True)


bot = discord.Bot()


@bot.command(integration_types={discord.IntegrationType.user_install})
async def command(ctx):
    await ctx.send_modal(Modal())


@bot.listen()
async def on_interaction(inter):
    print(inter.data)


bot.run("TOKEN")

@plun1331 plun1331 added bug Something isn't working feature Implements a feature upcoming discord feature Involves a feature not yet fully released by Discord labels Sep 18, 2025
@plun1331 plun1331 self-assigned this Sep 18, 2025
@plun1331 plun1331 added this to the v2.7 milestone Sep 18, 2025
Comment on lines 166 to 169
def values(self) -> list[Attachment] | None:
"""The files that were uploaded to the field."""
if self._interaction is None:
return None
Copy link
Contributor

@Soheab Soheab Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a user's POV, wouldn't it be better for this to always be a list?

Also missing return type in doc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to represent it as None when the modal hasn't been interacted yet, since an empty list would imply that the modal has been interacted with, but nothing was uploaded to it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to represent it as None

I agree

Copy link
Member

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add example

@NeloBlivion
Copy link
Member

Will review after #2904 , generally looks fine aside from existing comments

Co-authored-by: Soheab <33902984+Soheab@users.noreply.github.com>
Signed-off-by: plun1331 <plun1331@gmail.com>
@plun1331 plun1331 requested a review from Copilot September 26, 2025 13:46
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for file upload components in Discord modals, implementing a new ui.FileUpload class that allows users to upload files through modal dialogs. This is currently locked to private beta and cannot be used publicly yet.

  • Added ui.FileUpload component for modals with file attachment functionality
  • Fixed modal component matching by ID to handle reordered items correctly
  • Updated documentation and enum definitions to support the new file upload component type

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
examples/modal_dialogs.py Updated example to demonstrate FileUpload usage in modals
docs/api/ui_kit.rst Added documentation entry for FileUpload class
docs/api/models.rst Added FileUpload to component documentation
docs/api/enums.rst Added file_upload component type enum documentation
discord/ui/modal.py Updated modal to support FileUpload components and fixed component matching
discord/ui/input_text.py Fixed potential KeyError for missing values
discord/ui/file_upload.py New FileUpload component implementation
discord/ui/init.py Added FileUpload import
discord/types/message.py Added ephemeral field to Attachment type
discord/types/components.py Added FileUploadComponent type definition
discord/enums.py Added file_upload component type enum
discord/components.py Implemented FileUpload component class
CHANGELOG.md Updated changelog with new features and bug fixes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: plun1331 <plun1331@gmail.com>
@Paillat-dev
Copy link
Member

Does this conflict with #2904 ?

@plun1331
Copy link
Member Author

plun1331 commented Oct 1, 2025

probably, i think this should merge first and we can rebase #2904 onto it just cus this one is already done

Copy link
Member

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm

plun1331 and others added 2 commits October 1, 2025 21:15
Co-authored-by: Paillat <paillat@pycord.dev>
Signed-off-by: plun1331 <plun1331@gmail.com>
Copy link
Member

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, tested, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature Implements a feature upcoming discord feature Involves a feature not yet fully released by Discord
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants