-
-
Notifications
You must be signed in to change notification settings - Fork 481
feat: FileUpload in Modal #2938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks for opening this pull request! 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 |
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") |
discord/ui/file_upload.py
Outdated
def values(self) -> list[Attachment] | None: | ||
"""The files that were uploaded to the field.""" | ||
if self._interaction is None: | ||
return None |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add example
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>
Co-authored-by: Soheab <33902984+Soheab@users.noreply.github.com> Signed-off-by: plun1331 <plun1331@gmail.com>
There was a problem hiding this 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>
Does this conflict with #2904 ? |
probably, i think this should merge first and we can rebase #2904 onto it just cus this one is already done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm
Co-authored-by: Paillat <paillat@pycord.dev> Signed-off-by: plun1331 <plun1331@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, tested, thx
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
examples, ...).
Checklist
type: ignore
comments were used, a comment is also left explaining why.