|
20 | 20 | import net.dv8tion.jda.annotations.ReplaceWith;
|
21 | 21 | import net.dv8tion.jda.api.components.Component;
|
22 | 22 | import net.dv8tion.jda.api.entities.Mentions;
|
| 23 | +import net.dv8tion.jda.api.entities.Message; |
23 | 24 | import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
24 | 25 | import net.dv8tion.jda.api.utils.data.DataArray;
|
25 | 26 | import net.dv8tion.jda.api.utils.data.DataObject;
|
| 27 | +import net.dv8tion.jda.internal.entities.EntityBuilder; |
26 | 28 | import net.dv8tion.jda.internal.entities.SelectMenuMentions;
|
27 | 29 | import net.dv8tion.jda.internal.interactions.InteractionImpl;
|
28 | 30 | import net.dv8tion.jda.internal.utils.EntityString;
|
@@ -205,6 +207,30 @@ public Mentions getAsMentions()
|
205 | 207 | return new SelectMenuMentions(interaction.getJDA(), interaction.getInteractionEntityBuilder(), interaction.getGuild(), resolved, value.getArray("values"));
|
206 | 208 | }
|
207 | 209 |
|
| 210 | + /** |
| 211 | + * Returns this component's value as a list of {@link net.dv8tion.jda.api.entities.Message.Attachment Attachment} objects. |
| 212 | + * |
| 213 | + * <p>You can check if {@link #getType()} is equal to {@link Component.Type#FILE_UPLOAD FILE_UPLOAD} to see if this method can be used safely! |
| 214 | + * |
| 215 | + * @throws IllegalStateException |
| 216 | + * If this ModalMapping cannot be represented as such. |
| 217 | + * |
| 218 | + * @return This component's value as a list of {@link net.dv8tion.jda.api.entities.Message.Attachment Attachment} objects |
| 219 | + */ |
| 220 | + @Nonnull |
| 221 | + public List<Message.Attachment> getAsAttachmentList() |
| 222 | + { |
| 223 | + if (type != Component.Type.FILE_UPLOAD) |
| 224 | + typeError("Message.Attachment"); |
| 225 | + |
| 226 | + final DataObject attachments = resolved.getObject("attachments"); |
| 227 | + final EntityBuilder entityBuilder = interaction.getJDA().getEntityBuilder(); |
| 228 | + return value.getArray("values") |
| 229 | + .stream(DataArray::getString) |
| 230 | + .map(id -> entityBuilder.createMessageAttachment(attachments.getObject(id))) |
| 231 | + .collect(Helpers.toUnmodifiableList()); |
| 232 | + } |
| 233 | + |
208 | 234 | @Override
|
209 | 235 | public String toString()
|
210 | 236 | {
|
|
0 commit comments