diff --git a/CHANGELOG.md b/CHANGELOG.md index d7e251d11e8..4ee5518b7a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Additions -* Added a new `Field` builder function. #57 +* Added a new `Field` builder function. #57 +* Added `Kord#getChannelOf` to request a type of channel. ## Changes diff --git a/core/src/main/kotlin/com/gitlab/kordlib/core/Kord.kt b/core/src/main/kotlin/com/gitlab/kordlib/core/Kord.kt index fd8605b3658..feb76151051 100644 --- a/core/src/main/kotlin/com/gitlab/kordlib/core/Kord.kt +++ b/core/src/main/kotlin/com/gitlab/kordlib/core/Kord.kt @@ -6,6 +6,7 @@ import com.gitlab.kordlib.common.annotation.KordUnsafe import com.gitlab.kordlib.common.entity.DiscordShard import com.gitlab.kordlib.common.entity.Snowflake import com.gitlab.kordlib.common.entity.Status +import com.gitlab.kordlib.common.exception.RequestException import com.gitlab.kordlib.core.builder.kord.KordBuilder import com.gitlab.kordlib.core.builder.kord.KordRestOnlyBuilder import com.gitlab.kordlib.core.cache.data.GuildData @@ -20,6 +21,7 @@ import com.gitlab.kordlib.core.gateway.MasterGateway import com.gitlab.kordlib.core.gateway.handler.GatewayEventInterceptor import com.gitlab.kordlib.core.supplier.EntitySupplier import com.gitlab.kordlib.core.supplier.EntitySupplyStrategy +import com.gitlab.kordlib.core.supplier.getChannelOfOrNull import com.gitlab.kordlib.gateway.Gateway import com.gitlab.kordlib.gateway.builder.PresenceBuilder import com.gitlab.kordlib.rest.builder.guild.GuildCreateBuilder @@ -103,6 +105,17 @@ class Kord( suspend fun getChannel(id: Snowflake, strategy: EntitySupplyStrategy<*> = resources.defaultStrategy): Channel? = strategy.supply(this).getChannelOrNull(id) + /** + * Requests to get the [Channel] as type [T] through the [strategy], + * returns null if the [Channel] isn't present or is not of type [T]. + * + * @throws [RequestException] if anything went wrong during the request. + */ + suspend inline fun getChannelOf( + id: Snowflake, + strategy: EntitySupplyStrategy<*> = resources.defaultStrategy, + ): T? = strategy.supply(this).getChannelOfOrNull(id) + suspend fun getGuild(id: Snowflake, strategy: EntitySupplyStrategy<*> = resources.defaultStrategy): Guild? = strategy.supply(this).getGuildOrNull(id) suspend fun getSelf(strategy: EntitySupplyStrategy<*> = resources.defaultStrategy): User =