Skip to content

Commit

Permalink
[Kord-Extensions#132] Convenience function to get a thread's parent m…
Browse files Browse the repository at this point in the history
…essage
  • Loading branch information
gdude2002 authored and DRSchlaubi committed Aug 28, 2022
1 parent b8d7ce8 commit 2cc8905
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

0 comments on commit 2cc8905

Please sign in to comment.