Skip to content

feat: FileUpload in Modal#2938

Merged
Lulalaby merged 38 commits into
masterfrom
feat/model3
Oct 15, 2025
Merged

feat: FileUpload in Modal#2938
Lulalaby merged 38 commits into
masterfrom
feat/model3

Conversation

@plun1331

@plun1331 plun1331 commented Sep 18, 2025

Copy link
Copy Markdown
Member

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

pycord-app Bot commented Sep 18, 2025

Copy link
Copy Markdown

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
Copy Markdown
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
@Lumabots

Lumabots commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

# type: ignore should be specific and could add an explanation so we know why we ignored it

i stole them from InputText, i really don't know why they're there

I will take a look tonight then

@Paillat-dev
Paillat-dev requested review from Lumabots and Soheab October 8, 2025 16:15
Comment thread discord/ui/file_upload.py Outdated
Comment thread discord/ui/file_upload.py Outdated
Comment thread discord/ui/file_upload.py Outdated
Comment thread discord/ui/file_upload.py
Comment thread discord/ui/file_upload.py
Comment thread discord/components.py Outdated
Comment thread discord/components.py Outdated
Comment thread discord/components.py
Comment thread discord/components.py Outdated
Co-authored-by: Soheab <[email protected]>
Signed-off-by: plun1331 <[email protected]>
plun1331 and others added 9 commits October 9, 2025 22:17
Co-authored-by: Soheab <[email protected]>
Signed-off-by: plun1331 <[email protected]>
Signed-off-by: plun1331 <[email protected]>
Co-authored-by: Soheab <[email protected]>
Signed-off-by: plun1331 <[email protected]>
Co-authored-by: Soheab <[email protected]>
Signed-off-by: plun1331 <[email protected]>
Co-authored-by: Soheab <[email protected]>
Signed-off-by: plun1331 <[email protected]>
Co-authored-by: Soheab <[email protected]>
Signed-off-by: plun1331 <[email protected]>
Paillat-dev
Paillat-dev previously approved these changes Oct 11, 2025
@Paillat-dev
Paillat-dev requested a review from Soheab October 11, 2025 11:55
Comment thread discord/ui/file_upload.py Outdated
Soheab

This comment was marked as resolved.

@Soheab Soheab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested.

Code
import discord


client = discord.Bot()


class UploadMe(discord.ui.Modal):
    def __init__(self) -> None:
        super().__init__(title="Upload a file")

        self.file = discord.ui.FileUpload(
            label="Upload a file",
        )
        self.add_item(self.file)

    async def callback(self, interaction: discord.Interaction) -> None:
        files = self.file.values or []
        print(files)
        await interaction.response.send_message(f"Uploaded {len(files)} files!")


@client.slash_command(
    contexts=[
        discord.InteractionContextType.guild,
    ],
    integration_types=[
        discord.IntegrationType.user_install,
    ],
)
async def upload(interaction: discord.Interaction) -> None:
    """Upload a file"""
    n = UploadMe()
    print(n.to_dict())
    await interaction.response.send_modal(n)


client.run("...")

@Paillat-dev
Paillat-dev dismissed Lumabots’s stale review October 11, 2025 13:28

type: ignore are good like that for now.

@plun1331
plun1331 enabled auto-merge (squash) October 11, 2025 20:30
@plun1331

Copy link
Copy Markdown
Member Author

@Lulalaby when able please :3

@Lulalaby Lulalaby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM
#2904 is next then ;)

Comment thread discord/components.py
@Lulalaby
Lulalaby disabled auto-merge October 15, 2025 19:28
@Lulalaby
Lulalaby merged commit c5a14eb into master Oct 15, 2025
28 checks passed
@Lulalaby
Lulalaby deleted the feat/model3 branch October 15, 2025 19:34
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.

7 participants