跳到主要内容
版本:3.3.0

万花丛中

从事件中获取对象

好友

@Listener
suspend fun FriendEvent.event() {
val friend = friend()
}

@Listener
suspend fun GroupEvent.event() {
val group = group()
}

频道与子频道

@Listener 
suspend fun GuildEvent.event() {
val guild = guild()
val channels: Items<Channel> = gulid.channels
}

从对象中获取属性

好友属性

val id = friend.id
val username = friend.username
val remark = friend.remark
val avatar = friend.avatar

延时发送&动态参数

@Filter("我叫{{name}}")
@Listener
suspend fun FriendMessageEvent.listen(@FilterValue("name") name: String) {
val friend = friend()
// 当然,不异步也行
bot.launch {
delay(3000)
friend.send("Hello, $name")
}
}

特殊消息

上传并发送图片

@Listener
suspend fun FriendMessageEvent.listen() {
val imgPath = Path("img/example.png")
val imgResource = Resource.of(imgPath)
val img = imgResource.toImage()

// send img to friend
friend().send(img)
}

群里at + 文本

@Listener
suspend fun GroupMessageEvent.listen() {
val authorId = author().id
val at = At(authorId)

group().send(at + "你好?".toText())
}