diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index 67e388ca72..4234bdd191 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -162,9 +162,9 @@ internal fun TextSource.toRawMessageEntities(offset: Int = 0): List.toRawMessageEntities(preOffset: Int = 0): List { var i = preOffset - return flatMap { - it.toRawMessageEntities(i).also { - i += it.maxByOrNull { it.length }!!.length + 1 + return flatMap { textSource -> + textSource.toRawMessageEntities(i).also { + i += it.maxByOrNull { it.length } ?.length ?: textSource.source.length } } }