EventChannel

expect abstract class EventChannel<out BaseEvent : Event> @MiraiInternalApi constructor(baseEventClass: KClass<out BaseEvent>, defaultCoroutineContext: CoroutineContext)

事件通道.

事件通道是监听事件的入口, 但不负责广播事件. 要广播事件, 使用 Event.broadcastIMirai.broadcastEvent.

获取事件通道

EventChannel 不可自行构造, 只能通过 GlobalEventChannel, BotEvent, 或基于一个通道的过滤等操作获得.

全局事件通道

GlobalEventChannel 是单例对象, 表示全局事件通道, 可以获取到在其中广播的所有事件.

BotEvent 事件通道

若只需要监听某个 Bot 的事件, 可通过 Bot.eventChannel 获取到这样的 EventChannel.

通道操作

对通道的操作

创建事件监听

监听器生命周期

阅读 EventChannel.subscribe 以获取监听器生命周期相关信息.

与 kotlinx-coroutines 交互

mirai EventChannel 设计比 kotlinx-coroutines 的 Flow 稳定版更早. EventChannel 的功能与 Flow 类似, 不过 EventChannelsubscribe (类似 Flow.collect) 时有优先级判定, 也允许拦截.

通过 Flow 接收事件

使用 EventChannel.asFlow 获得 Flow, 然后可使用 Flow.collect 等操作.

转发事件到 SendChannel

使用 EventChannel.forwardToChannel 可将事件转发到指定 SendChannel.

actual abstract class EventChannel<out BaseEvent : Event> @MiraiInternalApi constructor(val baseEventClass: KClass<out BaseEvent>, val defaultCoroutineContext: CoroutineContext)

事件通道.

事件通道是监听事件的入口, 但不负责广播事件. 要广播事件, 使用 Event.broadcastIMirai.broadcastEvent.

获取事件通道

EventChannel 不可自行构造, 只能通过 GlobalEventChannel, BotEvent, 或基于一个通道的过滤等操作获得.

全局事件通道

GlobalEventChannel 是单例对象, 表示全局事件通道, 可以获取到在其中广播的所有事件.

BotEvent 事件通道

若只需要监听某个 Bot 的事件, 可通过 Bot.eventChannel 获取到这样的 EventChannel.

通道操作

对通道的操作

创建事件监听

监听器生命周期

阅读 EventChannel.subscribe 以获取监听器生命周期相关信息.

与 kotlinx-coroutines 交互

mirai EventChannel 设计比 kotlinx-coroutines 的 Flow 稳定版更早. EventChannel 的功能与 Flow 类似, 不过 EventChannelsubscribe (类似 Flow.collect) 时有优先级判定, 也允许拦截.

通过 Flow 接收事件

使用 EventChannel.asFlow 获得 Flow, 然后可使用 Flow.collect 等操作.

转发事件到 SendChannel

使用 EventChannel.forwardToChannel 可将事件转发到指定 SendChannel.

actual abstract class EventChannel<out BaseEvent : Event> @MiraiInternalApi constructor(val baseEventClass: KClass<out BaseEvent>, val defaultCoroutineContext: CoroutineContext)

事件通道.

事件通道是监听事件的入口, 但不负责广播事件. 要广播事件, 使用 Event.broadcastIMirai.broadcastEvent.

获取事件通道

EventChannel 不可自行构造, 只能通过 GlobalEventChannel, BotEvent, 或基于一个通道的过滤等操作获得.

全局事件通道

GlobalEventChannel 是单例对象, 表示全局事件通道, 可以获取到在其中广播的所有事件.

BotEvent 事件通道

若只需要监听某个 Bot 的事件, 可通过 Bot.eventChannel 获取到这样的 EventChannel.

通道操作

对通道的操作

创建事件监听

监听器生命周期

阅读 EventChannel.subscribe 以获取监听器生命周期相关信息.

与 kotlinx-coroutines 交互

mirai EventChannel 设计比 kotlinx-coroutines 的 Flow 稳定版更早. EventChannel 的功能与 Flow 类似, 不过 EventChannelsubscribe (类似 Flow.collect) 时有优先级判定, 也允许拦截.

通过 Flow 接收事件

使用 EventChannel.asFlow 获得 Flow, 然后可使用 Flow.collect 等操作.

转发事件到 SendChannel

使用 EventChannel.forwardToChannel 可将事件转发到指定 SendChannel.

Constructors

Link copied to clipboard
expect fun <out BaseEvent : Event> EventChannel(baseEventClass: KClass<out BaseEvent>, defaultCoroutineContext: CoroutineContext)
actual fun <out BaseEvent : Event> EventChannel(baseEventClass: KClass<out BaseEvent>, defaultCoroutineContext: CoroutineContext)
actual fun <out BaseEvent : Event> EventChannel(baseEventClass: KClass<out BaseEvent>, defaultCoroutineContext: CoroutineContext)

Functions

Link copied to clipboard
fun asChannel(    capacity: Int = Channel.RENDEZVOUS,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrency: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.NORMAL): <Error class: unknown class><out BaseEvent>

创建事件监听并将监听结果发送在 Channel. 将返回值 关闭Channel.close 时将会同时关闭事件监听.

Link copied to clipboard
expect abstract fun asFlow(): Flow<BaseEvent>

通过 Flow 接收此通道内的所有事件.

actual abstract fun asFlow(): Flow<BaseEvent>

通过 Flow 接收此通道内的所有事件.

actual abstract fun asFlow(): Flow<BaseEvent>

通过 Flow 接收此通道内的所有事件.

Link copied to clipboard
expect abstract fun context(vararg coroutineContexts: CoroutineContext): EventChannel<BaseEvent>

创建一个新的 EventChannel, 该 EventChannel 包含 this.coroutineContext 和添加的 coroutineContexts. coroutineContexts 会覆盖 defaultCoroutineContext 中的重复元素.

actual abstract fun context(vararg coroutineContexts: CoroutineContext): EventChannel<BaseEvent>

创建一个新的 EventChannel, 该 EventChannel 包含 this.coroutineContext 和添加的 coroutineContexts. coroutineContexts 会覆盖 defaultCoroutineContext 中的重复元素.

actual abstract fun context(vararg coroutineContexts: CoroutineContext): EventChannel<BaseEvent>

创建一个新的 EventChannel, 该 EventChannel 包含 this.coroutineContext 和添加的 coroutineContexts. coroutineContexts 会覆盖 defaultCoroutineContext 中的重复元素.

Link copied to clipboard
expect fun exceptionHandler(coroutineExceptionHandler: (exception: Throwable) -> Unit): EventChannel<BaseEvent>

创建一个新的 EventChannel, 该 EventChannel 包含 this.coroutineContext 和添加的 coroutineExceptionHandler

expect fun exceptionHandler(coroutineExceptionHandler: CoroutineExceptionHandler): EventChannel<BaseEvent>

创建一个新的 EventChannel, 该 EventChannel 包含 this.coroutineContext 和添加的 coroutineExceptionHandler

fun exceptionHandler(coroutineExceptionHandler: Consumer<Throwable>): EventChannel<BaseEvent>
actual fun exceptionHandler(coroutineExceptionHandler: (exception: Throwable) -> Unit): EventChannel<BaseEvent>

创建一个新的 EventChannel, 该 EventChannel 包含 this.coroutineContext 和添加的 coroutineExceptionHandler

actual fun exceptionHandler(coroutineExceptionHandler: (exception: Throwable) -> Unit): EventChannel<BaseEvent>

创建一个新的 EventChannel, 该 EventChannel 包含 this.coroutineContext 和添加的 coroutineExceptionHandler

actual fun exceptionHandler(coroutineExceptionHandler: CoroutineExceptionHandler): EventChannel<BaseEvent>

创建一个新的 EventChannel, 该 EventChannel 包含 this.coroutineContext 和添加的 coroutineExceptionHandler

Link copied to clipboard
expect fun filter(filter: (event: BaseEvent) -> Boolean): EventChannel<BaseEvent>

EventChannel.filter 的 Java 版本.

expect fun filter(filter: suspend (event: BaseEvent) -> Boolean): EventChannel<BaseEvent>

添加一个过滤器. 过滤器将在收到任何事件之后, 传递给通过 EventChannel.subscribe 注册的监听器之前调用.

actual fun filter(filter: (event: BaseEvent) -> Boolean): EventChannel<BaseEvent>

EventChannel.filter 的 Java 版本.

actual fun filter(filter: suspend (event: BaseEvent) -> Boolean): EventChannel<BaseEvent>

添加一个过滤器. 过滤器将在收到任何事件之后, 传递给通过 EventChannel.subscribe 注册的监听器之前调用.

actual fun filter(filter: (event: BaseEvent) -> Boolean): EventChannel<BaseEvent>

EventChannel.filter 的 Java 版本.

actual fun filter(filter: suspend (event: BaseEvent) -> Boolean): EventChannel<BaseEvent>

添加一个过滤器. 过滤器将在收到任何事件之后, 传递给通过 EventChannel.subscribe 注册的监听器之前调用.

Link copied to clipboard
expect inline fun <E : Event> filterIsInstance(): EventChannel<E>
expect fun <E : Event> filterIsInstance(kClass: KClass<out E>): EventChannel<E>

过滤事件的类型. 返回一个只包含 E 类型事件的 EventChannel

actual inline fun <E : Event> filterIsInstance(): EventChannel<E>
fun <E : Event> filterIsInstance(clazz: Class<out E>): EventChannel<E>
actual fun <E : Event> filterIsInstance(kClass: KClass<out E>): EventChannel<E>

过滤事件的类型. 返回一个只包含 E 类型事件的 EventChannel

actual inline fun <E : Event> filterIsInstance(): EventChannel<E>
actual fun <E : Event> filterIsInstance(kClass: KClass<out E>): EventChannel<E>

过滤事件的类型. 返回一个只包含 E 类型事件的 EventChannel

Link copied to clipboard
expect fun forwardToChannel(    channel: SendChannel<@UnsafeVariance BaseEvent>,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     priority: EventPriority = EventPriority.MONITOR): Listener<@UnsafeVariance BaseEvent>

创建事件监听并将监听结果转发到 channel. 当 Channel.send 抛出 ClosedSendChannelException 时停止 Listener 监听和转发.

actual fun forwardToChannel(    channel: SendChannel<BaseEvent>,     coroutineContext: CoroutineContext,     priority: EventPriority): Listener<BaseEvent>

创建事件监听并将监听结果转发到 channel. 当 Channel.send 抛出 ClosedSendChannelException 时停止 Listener 监听和转发.

Link copied to clipboard
expect fun parentJob(job: Job): EventChannel<BaseEvent>

指定协程父 Job. 之后在此 EventChannel 下创建的事件监听器都会成为 job 的子任务, 当 job 被取消时, 所有的事件监听器都会被取消.

actual fun parentJob(job: Job): EventChannel<BaseEvent>

指定协程父 Job. 之后在此 EventChannel 下创建的事件监听器都会成为 job 的子任务, 当 job 被取消时, 所有的事件监听器都会被取消.

Link copied to clipboard
expect fun parentScope(coroutineScope: CoroutineScope): EventChannel<BaseEvent>

coroutineScope 作为这个 EventChannel 的父作用域.

actual fun parentScope(coroutineScope: CoroutineScope): EventChannel<BaseEvent>

coroutineScope 作为这个 EventChannel 的父作用域.

Link copied to clipboard
fun registerListenerHost(host: ListenerHost, coroutineContext: CoroutineContext = EmptyCoroutineContext)

注册 ListenerHost 中的所有 EventHandler 标注的方法到这个 EventChannel. 查看 EventHandler.

Link copied to clipboard
expect inline fun <E : Event> subscribe(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrency: ConcurrencyKind = LOCKED,     priority: EventPriority = EventPriority.NORMAL,     noinline handler: suspend E.(E) -> ListeningStatus): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件.

expect fun <E : Event> subscribe(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrency: ConcurrencyKind = LOCKED,     priority: EventPriority = EventPriority.NORMAL,     handler: suspend E.(E) -> ListeningStatus): Listener<E>

subscribe 的区别是接受 eventClass 参数, 而不使用 reified 泛型. 通常推荐使用具体化类型参数.

actual inline fun <E : Event> subscribe(    coroutineContext: CoroutineContext,     concurrency: ConcurrencyKind,     priority: EventPriority,     noinline handler: suspend E.(E) -> ListeningStatus): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件.

fun <E : Event> subscribe(    eventClass: Class<out E>,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrency: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.NORMAL,     handler: Function<E, ListeningStatus>): Listener<E>

Java API. 查看 subscribe 获取更多信息.

actual fun <E : Event> subscribe(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext,     concurrency: ConcurrencyKind,     priority: EventPriority,     handler: suspend E.(E) -> ListeningStatus): Listener<E>

subscribe 的区别是接受 eventClass 参数, 而不使用 reified 泛型. 通常推荐使用具体化类型参数.

actual inline fun <E : Event> subscribe(    coroutineContext: CoroutineContext,     concurrency: ConcurrencyKind,     priority: EventPriority,     noinline handler: suspend E.(E) -> ListeningStatus): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件.

actual fun <E : Event> subscribe(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext,     concurrency: ConcurrencyKind,     priority: EventPriority,     handler: suspend E.(E) -> ListeningStatus): Listener<E>

subscribe 的区别是接受 eventClass 参数, 而不使用 reified 泛型. 通常推荐使用具体化类型参数.

Link copied to clipboard
expect inline fun <E : Event> subscribeAlways(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrency: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.NORMAL,     noinline handler: suspend E.(E) -> Unit): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件. 每当 事件广播 时, handler 都会被执行.

expect fun <E : Event> subscribeAlways(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrency: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.NORMAL,     handler: suspend E.(E) -> Unit): Listener<E>
actual inline fun <E : Event> subscribeAlways(    coroutineContext: CoroutineContext,     concurrency: ConcurrencyKind,     priority: EventPriority,     noinline handler: suspend E.(E) -> Unit): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件. 每当 事件广播 时, handler 都会被执行.

fun <E : Event> subscribeAlways(    eventClass: Class<out E>,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrency: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.NORMAL,     handler: Consumer<E>): Listener<E>

Java API. 查看 subscribeAlways 获取更多信息.

actual fun <E : Event> subscribeAlways(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext,     concurrency: ConcurrencyKind,     priority: EventPriority,     handler: suspend E.(E) -> Unit): Listener<E>
actual inline fun <E : Event> subscribeAlways(    coroutineContext: CoroutineContext,     concurrency: ConcurrencyKind,     priority: EventPriority,     noinline handler: suspend E.(E) -> Unit): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件. 每当 事件广播 时, handler 都会被执行.

actual fun <E : Event> subscribeAlways(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext,     concurrency: ConcurrencyKind,     priority: EventPriority,     handler: suspend E.(E) -> Unit): Listener<E>
Link copied to clipboard
expect inline fun <E : Event> subscribeOnce(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     priority: EventPriority = EventPriority.NORMAL,     noinline handler: suspend E.(E) -> Unit): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件, 只监听一次. 当 事件广播 时, handler 会被执行.

expect fun <E : Event> subscribeOnce(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     priority: EventPriority = EventPriority.NORMAL,     handler: suspend E.(E) -> Unit): Listener<E>
actual inline fun <E : Event> subscribeOnce(    coroutineContext: CoroutineContext,     priority: EventPriority,     noinline handler: suspend E.(E) -> Unit): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件, 只监听一次. 当 事件广播 时, handler 会被执行.

actual fun <E : Event> subscribeOnce(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext,     priority: EventPriority,     handler: suspend E.(E) -> Unit): Listener<E>

fun <E : Event> subscribeOnce(    eventClass: Class<out E>,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrency: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.NORMAL,     handler: Consumer<E>): Listener<E>

Java API. 查看 subscribeOnce 获取更多信息.

actual inline fun <E : Event> subscribeOnce(    coroutineContext: CoroutineContext,     priority: EventPriority,     noinline handler: suspend E.(E) -> Unit): Listener<E>

创建一个事件监听器, 监听事件通道中所有 E 及其子类事件, 只监听一次. 当 事件广播 时, handler 会被执行.

actual fun <E : Event> subscribeOnce(    eventClass: KClass<out E>,     coroutineContext: CoroutineContext,     priority: EventPriority,     handler: suspend E.(E) -> Unit): Listener<E>

Properties

Link copied to clipboard
expect val baseEventClass: KClass<out BaseEvent>
actual val baseEventClass: KClass<out BaseEvent>
actual val baseEventClass: KClass<out BaseEvent>
Link copied to clipboard
expect val defaultCoroutineContext: CoroutineContext

此事件通道的默认 CoroutineScope.coroutineContext. 将会被添加给所有注册的事件监听器.

actual val defaultCoroutineContext: CoroutineContext

此事件通道的默认 CoroutineScope.coroutineContext. 将会被添加给所有注册的事件监听器.

actual val defaultCoroutineContext: CoroutineContext

此事件通道的默认 CoroutineScope.coroutineContext. 将会被添加给所有注册的事件监听器.

Inheritors

Link copied to clipboard

Extensions

Link copied to clipboard
inline suspend fun <E : Event> EventChannel<*>.nextEvent(priority: EventPriority = EventPriority.NORMAL, noinline filter: suspend (E) -> Boolean = { true }): E
inline suspend fun <E : Event> EventChannel<*>.nextEvent(    priority: EventPriority = EventPriority.NORMAL,     intercept: Boolean = false,     noinline filter: suspend (E) -> Boolean = { true }): E

挂起当前协程, 直到监听到事件 E 的广播并通过 filter, 返回这个事件实例.

Link copied to clipboard
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribe(    crossinline handler: suspend E.(E) -> ListeningStatus,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribe(    crossinline handler: (E) -> ListeningStatus,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 带接收者的挂起函数的函数引用的监听方式.

@JvmName(name = "subscribe1")
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribe(    crossinline handler: suspend (E) -> ListeningStatus,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 挂起函数的函数引用的监听方式.

inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribe(    crossinline handler: E.(E) -> ListeningStatus,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 带接收者的函数的函数引用的监听方式.

Link copied to clipboard
@JvmName(name = "subscribeAlways1")
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribeAlways(    crossinline handler: suspend (E) -> Unit,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 挂起函数的函数引用的监听方式.

inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribeAlways(    crossinline handler: suspend E.(E) -> Unit,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribeAlways(    crossinline handler: (E) -> Unit,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 带接收者的挂起函数的函数引用的监听方式.

inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribeAlways(    crossinline handler: E.(E) -> Unit,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 带接收者的函数的函数引用的监听方式.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeFriendMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: FriendMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有好友消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeGroupMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: GroupMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有群会话消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeGroupTempMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: GroupTempMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有 GroupTempMessageEvent. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: MessageEventSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有联系人的消息事件.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeOtherClientMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: OtherClientMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有 OtherClient 消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeStrangerMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: StrangerMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有 Stranger 消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeUserMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: UserMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所 User 消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
inline suspend fun <E : Event, R : Any> EventChannel<*>.syncFromEvent(priority: EventPriority = EventPriority.NORMAL, noinline mapper: suspend (E) -> R?): R

挂起当前协程, 监听事件 E, 并尝试从这个事件中获取一个值, 在超时时抛出 TimeoutCancellationException