commonMain.builder.message.create.MessageCreateBuilder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-rest Show documentation
Show all versions of kord-rest Show documentation
Idiomatic Kotlin Wrapper for The Discord API
package dev.kord.rest.builder.message.create
import dev.kord.common.annotation.KordDsl
import dev.kord.common.entity.MessageFlag
import dev.kord.common.entity.MessageFlags
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.delegate.delegate
import dev.kord.rest.NamedFile
import dev.kord.rest.builder.component.ActionRowBuilder
import dev.kord.rest.builder.component.MessageComponentBuilder
import dev.kord.rest.builder.message.AllowedMentionsBuilder
import dev.kord.rest.builder.message.AttachmentBuilder
import dev.kord.rest.builder.message.EmbedBuilder
import dev.kord.rest.builder.message.MessageBuilder
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import dev.kord.rest.builder.message.actionRow as actionRowExtensionOnNewSupertype
import dev.kord.rest.builder.message.allowedMentions as allowedMentionsExtensionOnNewSupertype
import dev.kord.rest.builder.message.embed as embedExtensionOnNewSupertype
import dev.kord.rest.builder.message.messageFlags as messageFlagsExtensionOnNewSupertype
/**
* The base builder for creating a new message.
*/
@KordDsl
public sealed interface MessageCreateBuilder : MessageBuilder {
/** Whether this message should be played as a text-to-speech message. */
public var tts: Boolean?
/**
* Optional custom [MessageFlags] to add to the message created.
*
* @see suppressEmbeds
* @see suppressNotifications
*/
override var flags: MessageFlags?
/** This message will not trigger push and desktop notifications. */
public var suppressNotifications: Boolean?
}
// this could have been combined with MessageCreateBuilder into a single sealed class, but it would have broken binary
// compatibility, because MessageCreateBuilder would have changed from interface to class
@Suppress("PropertyName")
@KordDsl
public sealed class AbstractMessageCreateBuilder : MessageCreateBuilder {
internal var _content: Optional = Optional.Missing()
final override var content: String? by ::_content.delegate()
internal var _tts: OptionalBoolean = OptionalBoolean.Missing
final override var tts: Boolean? by ::_tts.delegate()
internal var _embeds: Optional> = Optional.Missing()
final override var embeds: MutableList? by ::_embeds.delegate()
internal var _allowedMentions: Optional = Optional.Missing()
final override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate()
internal var _components: Optional> = Optional.Missing()
final override var components: MutableList? by ::_components.delegate()
override val files: MutableList = mutableListOf()
internal var _attachments: Optional> = Optional.Missing()
final override var attachments: MutableList? by ::_attachments.delegate()
final override var flags: MessageFlags? = null
final override var suppressEmbeds: Boolean? = null
final override var suppressNotifications: Boolean? = null
}
/**
* Adds an embed to the message, configured by the [block]. A message can have up to 10 embeds.
*/
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated(
"Replaced by extension on 'MessageBuilder'. Change import to 'dev.kord.rest.builder.message.embed'.",
ReplaceWith("this.embed(block)", imports = ["dev.kord.rest.builder.message.embed"]),
DeprecationLevel.ERROR,
)
public inline fun MessageCreateBuilder.embed(block: EmbedBuilder.() -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
embedExtensionOnNewSupertype(block)
}
/**
* Configures the mentions that should trigger a mention (aka ping). Not calling this function will result in the default behavior
* (ping everything), calling this function but not configuring it before the request is build will result in all
* pings being ignored.
*/
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated(
"Replaced by extension on 'MessageBuilder'. Change import to 'dev.kord.rest.builder.message.allowedMentions'.",
ReplaceWith("this.allowedMentions(block)", imports = ["dev.kord.rest.builder.message.allowedMentions"]),
DeprecationLevel.ERROR,
)
public inline fun MessageCreateBuilder.allowedMentions(block: AllowedMentionsBuilder.() -> Unit = {}) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
allowedMentionsExtensionOnNewSupertype(block)
}
/**
* Adds an Action Row to the message, configured by the [builder]. A message can have up to 5 action rows.
*/
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated(
"Replaced by extension on 'MessageBuilder'. Change import to 'dev.kord.rest.builder.message.actionRow'.",
ReplaceWith("this.actionRow(builder)", imports = ["dev.kord.rest.builder.message.actionRow"]),
DeprecationLevel.ERROR,
)
public inline fun MessageCreateBuilder.actionRow(builder: ActionRowBuilder.() -> Unit) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
actionRowExtensionOnNewSupertype(builder)
}
/**
* Sets the [MessageFlags] for the created message.
*
* **Only supports [MessageFlag.SuppressEmbeds] and [MessageFlag.SuppressNotifications]**
*/
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated(
"Replaced by extension on 'MessageBuilder'. Change import to 'dev.kord.rest.builder.message.messageFlags'.",
ReplaceWith("this.messageFlags(builder)", imports = ["dev.kord.rest.builder.message.messageFlags"]),
DeprecationLevel.ERROR,
)
public inline fun MessageCreateBuilder.messageFlags(builder: MessageFlags.Builder.() -> Unit) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
messageFlagsExtensionOnNewSupertype(builder)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy