From 2cc8905bffa2fe1e3db192dd9d412a524942c69a Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 2 Feb 2022 20:47:13 +0000 Subject: [PATCH] [#132] Convenience function to get a thread's parent message --- .../kotlindiscord/kord/extensions/utils/_Channel.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/utils/_Channel.kt b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/utils/_Channel.kt index 2467c14918..719d564ae8 100644 --- a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/utils/_Channel.kt +++ b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/utils/_Channel.kt @@ -10,6 +10,7 @@ import dev.kord.common.entity.Permissions import dev.kord.common.entity.Snowflake import dev.kord.core.behavior.UserBehavior import dev.kord.core.behavior.channel.createWebhook +import dev.kord.core.entity.Message import dev.kord.core.entity.Webhook import dev.kord.core.entity.channel.GuildChannel import dev.kord.core.entity.channel.TopGuildChannel @@ -77,3 +78,14 @@ public suspend fun GuildChannel.permissionsForMember(memberId: Snowflake): Permi */ public suspend fun GuildChannel.permissionsForMember(user: UserBehavior): Permissions = permissionsForMember(user.id) + +/** + * Convenience function that returns the thread's parent message, if it was created from one. + * + * If it wasn't, or the parent channel can't be found, this function returns `null`. + */ +public suspend fun ThreadChannel.getParentMessage(): Message? { + val parentChannel = getParentOrNull() ?: return null + + return parentChannel.getMessageOrNull(this.id) +}