Package me.jakejmattson.discordkt.extensions

Extension functions to aid in bot development.

Types

Link copied to clipboard
object DiscordRegex

A collection of Regex for detecting discord strings

Link copied to clipboard
data class MessageParts(    val guildId: Snowflake,     val channelId: Snowflake,     val messageId: Snowflake)

The 3 snowflake elements of a message link.

Link copied to clipboard
object TimeStamp

Generate discord timestamps.

Link copied to clipboard
enum TimeStyle : Enum<TimeStyle>

Enum for discord timestamp styles.

Functions

Link copied to clipboard
fun EmbedBuilder.addField(name: String, value: String)

Add a field to an embed. Shorthand for the equivalent builder.

Link copied to clipboard
fun EmbedBuilder.addInlineField(name: String, value: String)

Add an inline field to an embed. Shorthand for the equivalent builder.

Link copied to clipboard
suspend fun Message.addReactions(vararg reactions: ReactionEmoji)
suspend fun Message.addReactions(reactions: List<ReactionEmoji>)

Add multiple ReactionEmoji to a Message.

Link copied to clipboard
fun EmbedBuilder.author(user: User)

Create an author field from the given User. Set's the name, icon, and url.

Link copied to clipboard
fun ActionRowBuilder.button(    label: String?,     emoji: DiscordEmoji?,     style: ButtonStyle = ButtonStyle.Secondary,     disabled: Boolean = false,     action: ButtonBuilder.InteractionButtonBuilder.() -> Unit)

Create an interaction button with a UUID.

Link copied to clipboard
fun MutableList<String>.consumeFirst(): String

Remove and return the first element in a mutable list.

Link copied to clipboard
fun Message.containsInvite(): Boolean

Checks if this message contains a Discord invite.

fun String.containsInvite(): Boolean

Whether this string contains a discord invite.

Link copied to clipboard
fun String.containsURl(): Boolean

Whether this string matches a URL regex.

Link copied to clipboard
suspend fun MessageChannelBehavior.createMenu(construct: suspend MenuBuilder.() -> Unit): Message

Create a new menu in a message channel.

Link copied to clipboard
fun User.descriptor(): String

User entity formatted to a readable String. username#1234 :: <@username>

Link copied to clipboard
suspend fun VoiceState.disconnect(): Member

Disconnect this Member from their VoiceChannel.

Link copied to clipboard
fun EmbedBuilder.footer(text: String, icon: String? = null)

Set the footer of an embed given its text and optional icon.

Link copied to clipboard
fun Message.getInvites(): List<String>

Find all invites in this message.

fun String.getInvites(): List<String>

Return all discord invites in this string.

Link copied to clipboard
fun User.idDescriptor(): String

User entity formatted to a readable String. username#1234 :: 123456789123456789

Link copied to clipboard
inline fun <T : Event> intentsOf(): Intents

Convert an Event to its Intents.

Link copied to clipboard
fun String.isBooleanValue(): Boolean

Whether this string is a valid boolean value (true/false/t/f).

Link copied to clipboard
fun Message.isImagePost(): Boolean

Checks if this message is exclusively an image.

Link copied to clipboard
fun UserBehavior.isSelf(): Boolean

Checks if this User is itself.

Link copied to clipboard
suspend fun Message.jumpLink(): String?

Determine the Discord URL for this message (null if in a DM).

Link copied to clipboard
suspend fun Message.mentionsSomeone(): Boolean

Checks if this message mentions a user or role.

Link copied to clipboard
suspend fun VoiceState.move(channel: VoiceChannel): Member

Move this Member to a new VoiceChannel.

Link copied to clipboard
fun Number.pluralize(unit: String): String

Create a string with a number and its respective singular/plural unit string.

Link copied to clipboard
operator fun Intent.plus(intent: Intent): Intents

Combine two Intent into Intents.

Link copied to clipboard
suspend fun Message.replySilently(builder: suspend UserMessageCreateBuilder.() -> Unit): Message

Reply to this message with no mentions allowed.

Link copied to clipboard
suspend fun String.sanitiseMentions(discord: Discord): String

Sanitize all mentions and replace them with their resolved discord names.

Link copied to clipboard
suspend fun UserBehavior.sendPrivateMessage(message: String): Message

Send the user a private string message.

suspend fun UserBehavior.sendPrivateMessage(embed: suspend EmbedBuilder.() -> Unit): Message

Send the user a private embed message.

Link copied to clipboard
fun User.simpleDescriptor(): String

User entity formatted to a readable String. <@username> (username#1234)

Link copied to clipboard
fun <T> stringify(entity: T): String

Convert any generic type into a more readable String.

Link copied to clipboard
fun EmbedBuilder.thumbnail(url: String)

Set the thumbnail of an embed given a URL.

Link copied to clipboard
fun ReactionEmoji.toPartialEmoji(): DiscordPartialEmoji

Convert a ReactionEmoji to a DiscordPartialEmoji.

fun DiscordEmoji.toPartialEmoji(): DiscordPartialEmoji

Convert a DiscordEmoji to a DiscordPartialEmoji.

Link copied to clipboard
fun Long.toSnowflake(): Snowflake

Convert a Long ID to a Snowflake.

fun String.toSnowflake(): Snowflake

Convert a String ID or mention to a Snowflake.

Link copied to clipboard
fun String.toSnowflakeOrNull(): Snowflake?

Convert an ID or mention to a Snowflake.

Link copied to clipboard
fun Long.toTimeString(trimLeadingZeroes: Boolean = true, trimTrailingZeros: Boolean = true): String

Convert this long value to a time string.

Link copied to clipboard
fun String.trimToID(): String

Trim any type of mention into an ID.

Link copied to clipboard
fun String.unwrapMessageLink(): MessageParts?

Unwrap a message link into its MessageParts.

Link copied to clipboard
fun uuid(): String

Generate a random UUID String.

Properties

Link copied to clipboard
val User.fullName: String

A User's name and discriminator username#1234

Link copied to clipboard
val UserBehavior.mutualGuilds: Flow<Guild>

Get guilds shared between the user and the bot.

Link copied to clipboard
val User.pfpUrl: String

A link to this user's profile picture.

Link copied to clipboard
val UserBehavior.profileLink: String

A Discord profile link for this user.