监听概览
消息发送
- Kotlin
- Java
ExampleListener.kt
@Listener // if use simboot
suspend fun GroupMessageEvent.listener() {
group().send("Hello Simbot")
}
ExampleListener.java
@Listener // if use simboot
public void listener(GroupMessageEvent event) {
event.getGroup().sendBlocking("Hello Simbot")
}
消息回复
- Kotlin
- Java
ExampleListener.kt
@Listener
suspend fun FriendMessageEvent.listener() {
reply("Hello Simbot")
}
ExampleListener.java
@Listener
public void listener(FriendMessageEvent event) {
event.replyBlocking("Hello Simbot");
}
成员获 取
- Kotlin
- Java
ExampleListener.kt
@Listener
suspend fun GroupMessageEvent.listener() {
group().members().collect {
logger.info("Member: {}", it)
}
}
ExampleListener.java
@Listener
public void listener(GroupMessageEvent event) {
event.getGroup().getMembers().forEach(member -> logger.info("Member: {}", member));
}