@@ -21,11 +21,11 @@ class FileUpload:
21
21
22
22
Parameters
23
23
----------
24
- custom_id: Optional[:class:`str`]
25
- The ID of the input text field that gets received during an interaction.
26
24
label: :class:`str`
27
25
The label for the file upload field.
28
26
Must be 45 characters or fewer.
27
+ custom_id: Optional[:class:`str`]
28
+ The ID of the input text field that gets received during an interaction.
29
29
description: Optional[:class:`str`]
30
30
The description for the file upload field.
31
31
Must be 100 characters or fewer.
@@ -58,8 +58,8 @@ class FileUpload:
58
58
def __init__ (
59
59
self ,
60
60
* ,
61
- custom_id : str | None = None ,
62
61
label : str ,
62
+ custom_id : str | None = None ,
63
63
min_values : int | None = None ,
64
64
max_values : int | None = None ,
65
65
required : bool | None = True ,
@@ -76,7 +76,7 @@ def __init__(
76
76
raise ValueError ("min_values must be between 0 and 10" )
77
77
if max_values and (max_values < 1 or max_values > 10 ):
78
78
raise ValueError ("max_length must be between 1 and 10" )
79
- if not isinstance (custom_id , str ) and custom_id is not None :
79
+ if custom_id is not None and not isinstance (custom_id , str ):
80
80
raise TypeError (
81
81
f"expected custom_id to be str, not { custom_id .__class__ .__name__ } "
82
82
)
@@ -92,8 +92,7 @@ def __init__(
92
92
required = required ,
93
93
id = id ,
94
94
)
95
- self ._interaction : Interaction | None = None
96
- self ._values : list [str ] | None = None
95
+ self ._attachments : list [Attachment ] | None = None
97
96
self .row = row
98
97
self ._rendered_row : int | None = None
99
98
@@ -165,17 +164,7 @@ def required(self, value: bool | None):
165
164
@property
166
165
def values (self ) -> list [Attachment ] | None :
167
166
"""The files that were uploaded to the field."""
168
- if self ._interaction is None :
169
- return None
170
- attachments = []
171
- for attachment_id in self ._values :
172
- attachment_data = self ._interaction .data ["resolved" ]["attachments" ][
173
- attachment_id
174
- ]
175
- attachments .append (
176
- Attachment (state = self ._interaction ._state , data = attachment_data )
177
- )
178
- return attachments
167
+ return self ._attachments
179
168
180
169
@property
181
170
def width (self ) -> int :
@@ -185,8 +174,13 @@ def to_component_dict(self) -> FileUploadComponentPayload:
185
174
return self ._underlying .to_dict ()
186
175
187
176
def refresh_from_modal (self , interaction : Interaction , data : dict ) -> None :
188
- self ._interaction = interaction
189
- self ._values = data .get ("values" , [])
177
+ values = data .get ("values" , [])
178
+ self ._attachments = [
179
+ Attachment (
180
+ state = interaction ._state ,
181
+ data = interaction .data ["resolved" ]["attachments" ][attachment_id ]
182
+ ) for attachment_id in values
183
+ ]
190
184
191
185
@staticmethod
192
186
def uses_label () -> bool :
0 commit comments