Skip to content

Commit

Permalink
Fix handling of passing null to setMessageReference (#2749)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment authored Oct 8, 2024
1 parent c54a3a5 commit e24fc59
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit e24fc59

Please sign in to comment.