44import club .minnced .discord .webhook .external .JDAWebhookClient ;
55import club .minnced .discord .webhook .receive .ReadonlyMessage ;
66import club .minnced .discord .webhook .send .AllowedMentions ;
7+ import club .minnced .discord .webhook .send .WebhookEmbedBuilder ;
78import club .minnced .discord .webhook .send .WebhookMessageBuilder ;
89import club .minnced .discord .webhook .send .component .LayoutComponent ;
910import net .dv8tion .jda .api .entities .Message ;
1011import net .dv8tion .jda .api .entities .Message .Attachment ;
12+ import net .dv8tion .jda .api .entities .MessageEmbed ;
1113import net .dv8tion .jda .api .entities .Webhook ;
1214import net .dv8tion .jda .api .entities .channel .attribute .IWebhookContainer ;
1315import org .jetbrains .annotations .NotNull ;
16+ import org .jetbrains .annotations .Nullable ;
1417
1518import java .util .List ;
1619import java .util .Optional ;
@@ -28,7 +31,7 @@ private WebhookUtil() {
2831 * Makes sure that a writable webhook exists in a specific channel. if no
2932 * suitable webhook is found, one is created.
3033 *
31- * @param channel the {@link StandardGuildMessageChannel } the webhook should exist in
34+ * @param channel the {@link IWebhookContainer } the webhook should exist in
3235 * @param callback an action that is executed once a webhook is
3336 * found/created
3437 */
@@ -40,7 +43,7 @@ public static void ensureWebhookExists(@NotNull IWebhookContainer channel, @NotN
4043 * Makes sure that a writable webhook exists in a specific channel. if no
4144 * suitable webhook is found, one is created.
4245 *
43- * @param channel the {@link StandardGuildMessageChannel } the webhook should exist in
46+ * @param channel the {@link IWebhookContainer } the webhook should exist in
4447 * @param callback an action that is executed once a webhook is
4548 * found/created
4649 * @param failureCallback an action that is executed if the webhook
@@ -68,20 +71,24 @@ public static void ensureWebhookExists(@NotNull IWebhookContainer channel, @NotN
6871 * @param newMessageContent the new (custom) content
6972 * @param threadId the thread to send the message in or {@code 0} if the
7073 * message should be sent directly
71- * @param components An optional array of {@link LayoutComponent}s.
74+ * @param components A nullable list of {@link LayoutComponent}s.
75+ * @param embeds A nullable list of {@link MessageEmbed}s.
7276 * @return a {@link CompletableFuture} representing the action of sending
7377 * the message
7478 */
75- public static CompletableFuture <ReadonlyMessage > mirrorMessageToWebhook (@ NotNull Webhook webhook , @ NotNull Message originalMessage , String newMessageContent , long threadId , LayoutComponent @ NotNull ... components ) {
79+ public static CompletableFuture <ReadonlyMessage > mirrorMessageToWebhook (@ NotNull Webhook webhook , @ NotNull Message originalMessage , String newMessageContent , long threadId , @ Nullable List < LayoutComponent > components , @ Nullable List < MessageEmbed > embeds ) {
7680 JDAWebhookClient client = new WebhookClientBuilder (webhook .getIdLong (), webhook .getToken ())
7781 .setThreadId (threadId ).buildJDA ();
7882 WebhookMessageBuilder message = new WebhookMessageBuilder ().setContent (newMessageContent )
7983 .setAllowedMentions (AllowedMentions .none ())
8084 .setAvatarUrl (originalMessage .getMember ().getEffectiveAvatarUrl ())
8185 .setUsername (originalMessage .getMember ().getEffectiveName ());
82- if (components . length > 0 ) {
86+ if (components != null && ! components . isEmpty () ) {
8387 message .addComponents (components );
8488 }
89+ if (embeds != null && !embeds .isEmpty ()) {
90+ message .addEmbeds (embeds .stream ().map (e -> WebhookEmbedBuilder .fromJDA (e ).build ()).toList ());
91+ }
8592 List <Attachment > attachments = originalMessage .getAttachments ();
8693 @ SuppressWarnings ("unchecked" )
8794 CompletableFuture <?>[] futures = new CompletableFuture <?>[attachments .size ()];
0 commit comments