Skip to content

Commit

Permalink
Fix handling of empty select menu interactions (#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Nov 13, 2022
1 parent f181320 commit ee33e95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -20,6 +20,7 @@
import net.dv8tion.jda.api.entities.Mentions;
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectInteraction;
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu;
import net.dv8tion.jda.api.utils.data.DataArray;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.entities.GuildImpl;
Expand All @@ -39,8 +40,8 @@ public EntitySelectInteractionImpl(JDAImpl jda, DataObject data)
this.mentions = new SelectMenuMentions(
jda,
(GuildImpl) getGuild(),
content.getObject("resolved"),
content.getArray("values")
content.optObject("resolved").orElseGet(DataObject::empty),
content.optArray("values").orElseGet(DataArray::empty)
);
}

Expand Down
Expand Up @@ -39,9 +39,10 @@ public StringSelectInteractionImpl(JDAImpl jda, DataObject data)

protected List<String> parseValues(DataObject data)
{
return data.getArray("values")
.stream(DataArray::getString)
.collect(Collectors.toList());
return data.optArray("values").map(arr ->
arr.stream(DataArray::getString)
.collect(Collectors.toList())
).orElse(Collections.emptyList());
}

@Nonnull
Expand Down

0 comments on commit ee33e95

Please sign in to comment.