Skip to content

Commit

Permalink
Optionally deserialize command contexts and integration types
Browse files Browse the repository at this point in the history
Discord says it's not null, but it is in guild commands
See discord/discord-api-docs#6744
  • Loading branch information
freya022 committed Mar 26, 2024
1 parent b920eb6 commit 6b474ed
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,18 @@ public CommandImpl(JDAImpl api, Guild guild, DataObject json)
: DefaultMemberPermissions.enabledFor(json.getLong("default_member_permissions"));

this.guildOnly = !json.getBoolean("dm_permission", true);
this.contexts = json.getArray("contexts").stream(DataArray::getString)
.map(InteractionContextType::fromKey)
.collect(Helpers.toUnmodifiableEnumSet(InteractionContextType.class));
this.integrationTypes = json.getArray("integration_types").stream(DataArray::getString)
.map(IntegrationType::fromKey)
.collect(Helpers.toUnmodifiableEnumSet(IntegrationType.class));
this.contexts = json.optArray("contexts")
.map(d -> d.stream(DataArray::getString)
.map(InteractionContextType::fromKey)
.collect(Helpers.toUnmodifiableEnumSet(InteractionContextType.class))
)
.orElse(EnumSet.noneOf(InteractionContextType.class));
this.integrationTypes = json.optArray("integration_types")
.map(d -> d.stream(DataArray::getString)
.map(IntegrationType::fromKey)
.collect(Helpers.toUnmodifiableEnumSet(IntegrationType.class))
)
.orElse(EnumSet.noneOf(IntegrationType.class));
this.nsfw = json.getBoolean("nsfw");
}

Expand Down

0 comments on commit 6b474ed

Please sign in to comment.