-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
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") |
I will take a look tonight then |
Co-authored-by: Soheab <[email protected]> Signed-off-by: plun1331 <[email protected]>
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]>
Signed-off-by: plun1331 <[email protected]>
Co-authored-by: Soheab <[email protected]> Signed-off-by: plun1331 <[email protected]>
Signed-off-by: plun1331 <[email protected]>
Signed-off-by: Soheab <[email protected]>
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.
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("...")
type: ignore are good like that for now.
@Lulalaby when able please :3 |
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
#2904 is next then ;)
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.