我有一个DiscordBot,它是使用Kotlin用Discord4j编写的.

fun sendEmbedMessage(gateway: GatewayDiscordClient, embed: EmbedCreateSpec, channelId: String) {
    gateway.getChannelById(Snowflake.of(channelId))
        .ofType(GuildMessageChannel::class.java)
        .flatMap { channel -> channel.createMessage(embed) }
        .subscribe()
}

提前感谢!

推荐答案

您可以使用publish:

fun sendEmbedMessage(gateway: GatewayDiscordClient, embed: EmbedCreateSpec, channelId: String) {
    gateway.getChannelById(Snowflake.of(channelId))
        .ofType(GuildMessageChannel::class.java)
        .flatMap { channel -> channel.createMessage(embed) }
        .flatMap { message -> message.publish() }
        .subscribe()
}

Kotlin相关问答推荐

Lambda和普通Kotlin函数有什么区别?

Android前台服务 list —Altbeacon

在Webflux应用程序中通过kotlin协程启动fire and forget job

如何在 Kotlin 中为类方法调用传递变量

Webpack 配置未应用于 kotlin 多平台react 项目

Kotlin .如何用从 1 到 90 的 5 个唯一数字填充列表中的每一行?

kotlin 父类具有依赖于抽象变量的变量

在子类中覆盖 kotlin 运算符扩展函数

在 kotlin 中重载函数时,我在一些非常基本的代码上不断收到类型不匹配

如何从 kotlin 函数中 Select 正确的枚举值

Spring webflux bean验证不起作用

致命错误 LifecycleOwners 必须在 registerForActivityResult 开始之前调用 register

Android Room - error: Cannot figure out how to save this field into database

未解决的参考 dagger 2 + kotlin + android gradle

指定为非null的参数在ArrayAdaper中为null

如何从协程范围返回值

Dagger +Kotlin 不注入

将 Double 转换为 ByteArray 或 Array Kotlin

Kotlin,什么时候按map授权?

Kotlin中的函数接口