From b5f136e08ea356f7ee9681c9eab24a31ee90bbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Spie=C3=9F?= Date: Tue, 8 Oct 2024 19:40:44 +0200 Subject: [PATCH] Fix handling of passing null to setMessageReference --- .../restaction/MessageCreateActionImpl.java | 9 +++++++-- .../test/restaction/MessageCreateActionTest.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/dv8tion/jda/internal/requests/restaction/MessageCreateActionImpl.java b/src/main/java/net/dv8tion/jda/internal/requests/restaction/MessageCreateActionImpl.java index 57e6dd3a5a..aa503838d9 100644 --- a/src/main/java/net/dv8tion/jda/internal/requests/restaction/MessageCreateActionImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/requests/restaction/MessageCreateActionImpl.java @@ -149,8 +149,13 @@ public MessageCreateAction setMessageReference(@Nonnull MessageReference.Message @Override public MessageCreateAction setMessageReference(@Nullable String messageId) { - if (messageId != null) - Checks.isSnowflake(messageId); + if (messageId == null) + { + this.messageReference = null; + return this; + } + + Checks.isSnowflake(messageId); String guildId = null; if (channel instanceof GuildChannel) guildId = ((GuildChannel) channel).getGuild().getId(); diff --git a/src/test/java/net/dv8tion/jda/test/restaction/MessageCreateActionTest.java b/src/test/java/net/dv8tion/jda/test/restaction/MessageCreateActionTest.java index 48b0aaff5b..b737315bf8 100644 --- a/src/test/java/net/dv8tion/jda/test/restaction/MessageCreateActionTest.java +++ b/src/test/java/net/dv8tion/jda/test/restaction/MessageCreateActionTest.java @@ -266,6 +266,21 @@ void testFullFromBuilder() .whenQueueCalled(); } + @Test + void testSetMessageReferenceNull() + { + MessageCreateActionImpl action = new MessageCreateActionImpl(channel); + + action.setMessageReference((String) null); + action.setContent("test content"); + action.failOnInvalidReply(true); + + assertThatRequestFrom(action) + .hasBodyEqualTo(defaultMessageRequest() + .put("content", "test content")) + .whenQueueCalled(); + } + @Nonnull protected DataObject normalizeRequestBody(@Nonnull DataObject body) {