diff --git a/common/src/commonMain/kotlin/entity/optional/Optional.kt b/common/src/commonMain/kotlin/entity/optional/Optional.kt index 561a6bd85e7..a9e43971c4f 100644 --- a/common/src/commonMain/kotlin/entity/optional/Optional.kt +++ b/common/src/commonMain/kotlin/entity/optional/Optional.kt @@ -325,3 +325,8 @@ public fun Optional.toPrimitive(): OptionalBoolean = when (this) { is Value -> OptionalBoolean.Value(value) is Missing, is Null<*> -> OptionalBoolean.Missing } + +public fun Optional>.missingOnEmpty(): Optional> = when (this) { + is Value -> if (value.isEmpty()) Missing() else this + is Missing, is Null<*> -> Missing() +} diff --git a/rest/src/commonMain/kotlin/builder/interaction/InputChatBuilders.kt b/rest/src/commonMain/kotlin/builder/interaction/InputChatBuilders.kt index 76cc48d66ce..efa654f92ff 100644 --- a/rest/src/commonMain/kotlin/builder/interaction/InputChatBuilders.kt +++ b/rest/src/commonMain/kotlin/builder/interaction/InputChatBuilders.kt @@ -9,6 +9,7 @@ import dev.kord.common.entity.Permissions import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.delegate.delegate import dev.kord.common.entity.optional.mapList +import dev.kord.common.entity.optional.missingOnEmpty import dev.kord.rest.json.request.ApplicationCommandCreateRequest import dev.kord.rest.json.request.ApplicationCommandModifyRequest import kotlin.contracts.InvocationKind @@ -171,8 +172,8 @@ internal class ChatInputCreateBuilderImpl( state.defaultMemberPermissions, state.dmPermission, @Suppress("DEPRECATION") state.defaultPermission, - integrationTypes = Optional.missingOnEmpty(state.integrationTypes), - contexts = missingOnEmpty(state.contexts), + integrationTypes = state.integrationTypes.missingOnEmpty(), + contexts = state.contexts.missingOnEmpty(), nsfw = state.nsfw, ) diff --git a/rest/src/commonMain/kotlin/builder/interaction/MessageCommandBuilders.kt b/rest/src/commonMain/kotlin/builder/interaction/MessageCommandBuilders.kt index bc118bea53c..224ea88f385 100644 --- a/rest/src/commonMain/kotlin/builder/interaction/MessageCommandBuilders.kt +++ b/rest/src/commonMain/kotlin/builder/interaction/MessageCommandBuilders.kt @@ -7,6 +7,7 @@ import dev.kord.common.entity.ApplicationIntegrationType import dev.kord.common.entity.InteractionContextType import dev.kord.common.entity.Permissions import dev.kord.common.entity.optional.delegate.delegate +import dev.kord.common.entity.optional.missingOnEmpty import dev.kord.rest.json.request.ApplicationCommandCreateRequest import dev.kord.rest.json.request.ApplicationCommandModifyRequest @@ -86,8 +87,8 @@ internal class MessageCommandCreateBuilderImpl(override var name: String) : Glob dmPermission = state.dmPermission, defaultMemberPermissions = state.defaultMemberPermissions, defaultPermission = @Suppress("DEPRECATION") state.defaultPermission, - integrationTypes = state.integrationTypes, - contexts = state.contexts, + integrationTypes = state.integrationTypes.missingOnEmpty(), + contexts = state.contexts.missingOnEmpty(), nsfw = state.nsfw, ) } diff --git a/rest/src/commonMain/kotlin/builder/interaction/UserCommandBuilders.kt b/rest/src/commonMain/kotlin/builder/interaction/UserCommandBuilders.kt index bfead739ed1..17f4a55427e 100644 --- a/rest/src/commonMain/kotlin/builder/interaction/UserCommandBuilders.kt +++ b/rest/src/commonMain/kotlin/builder/interaction/UserCommandBuilders.kt @@ -7,6 +7,7 @@ import dev.kord.common.entity.ApplicationIntegrationType import dev.kord.common.entity.InteractionContextType import dev.kord.common.entity.Permissions import dev.kord.common.entity.optional.delegate.delegate +import dev.kord.common.entity.optional.missingOnEmpty import dev.kord.rest.json.request.ApplicationCommandCreateRequest import dev.kord.rest.json.request.ApplicationCommandModifyRequest @@ -81,8 +82,8 @@ internal class UserCommandCreateBuilderImpl(override var name: String) : GlobalU defaultMemberPermissions = state.defaultMemberPermissions, dmPermission = state.dmPermission, defaultPermission = @Suppress("DEPRECATION") state.defaultPermission, - integrationTypes = state.integrationTypes, - contexts = state.contexts, + integrationTypes = state.integrationTypes.missingOnEmpty(), + contexts = state.contexts.missingOnEmpty(), nsfw = state.nsfw, ) }