|
8 | 8 | import com.javadiscord.jdi.internal.api.DiscordRequest;
|
9 | 9 | import com.javadiscord.jdi.internal.api.DiscordRequestBuilder;
|
10 | 10 |
|
11 |
| -import java.io.FileNotFoundException; |
12 | 11 | import java.nio.file.Path;
|
13 | 12 | import java.util.HashMap;
|
14 | 13 | import java.util.List;
|
@@ -46,25 +45,22 @@ public DiscordRequestBuilder create() {
|
46 | 45 | messageReferences.ifPresent(val -> body.put("message_reference", val));
|
47 | 46 | components.ifPresent(val -> body.put("components", val));
|
48 | 47 | stickerIds.ifPresent(val -> body.put("sticker_ids", val));
|
49 |
| - payloadJson.ifPresent(val -> body.put("payload_json", val)); |
50 | 48 | flags.ifPresent(val -> body.put("flags", val));
|
51 | 49 | enforceNonce.ifPresent(val -> body.put("enforce_nonce", val));
|
52 | 50 |
|
53 |
| - bodyBuilder.textPart("payload_json", body); |
| 51 | + if (payloadJson.isPresent()) { |
54 | 52 |
|
55 |
| - files.ifPresent( |
56 |
| - paths -> { |
57 |
| - for (int i = 0; i < paths.size(); i++) { |
58 |
| - try { |
59 |
| - bodyBuilder.filePart("file[%d]".formatted(i), paths.get(i)); |
60 |
| - } catch (FileNotFoundException ignored) { |
61 |
| - } |
62 |
| - } |
63 |
| - }); |
| 53 | + bodyBuilder.textPart("payload_json", body); |
| 54 | + |
| 55 | + return new DiscordRequestBuilder() |
| 56 | + .post() |
| 57 | + .path("/channels/%s/messages".formatted(channelId)) |
| 58 | + .multipartBody(bodyBuilder.build()); |
| 59 | + } |
64 | 60 |
|
65 | 61 | return new DiscordRequestBuilder()
|
66 | 62 | .post()
|
67 | 63 | .path("/channels/%s/messages".formatted(channelId))
|
68 |
| - .multipartBody(bodyBuilder.build()); |
| 64 | + .body(body); |
69 | 65 | }
|
70 | 66 | }
|
0 commit comments