This commit is contained in:
Him188 2020-02-20 16:40:40 +08:00
parent a0843c1da5
commit cdd3053e16

View File

@ -36,7 +36,7 @@ JDK要求8以上
- 首先添加repositories
```
```groovy
//添加jcenter仓库
/*
repositories {
@ -53,7 +53,7 @@ JDK要求8以上
- 添加依赖将dependencies部分覆盖为
```
```groovy
dependencies {
implementation 'net.mamoe:mirai-core:0.16.0'
implementation 'net.mamoe:mirai-core-qqandroid-jvm:0.16.0'
@ -72,38 +72,31 @@ JDK要求8以上
- 在包下新建kotlin文件```MyLoader.kt```
```
package net.mamoe.mirai.simpleloader
import kotlinx.coroutines.*
import net.mamoe.mirai.Bot
import net.mamoe.mirai.alsoLogin
import net.mamoe.mirai.event.subscribeMessages
fun main(args: Array<String>) {
runBlocking {//阻塞直到Mirai退出
coroutineScope() {
launch {
val qqId = 10000L//Bot的QQ号需为Long类型在结尾处添加大写L
val password = "your_password"//Bot的密码
val miraiBot = Bot(qqId, password).alsoLogin()//新建Bot并登陆
miraiBot.subscribeMessages {
"你好" reply "你好!"
"profile" reply { sender.queryProfile() }
case("at me") {
reply(sender.at() + " 给爷爬 ")
}
(contains("舔") or contains("刘老板")) {
"刘老板太强了".reply()
}
}
miraiBot.join()
}
}
}
}
```
```kotlin
package net.mamoe.mirai.simpleloader
import kotlinx.coroutines.*
import net.mamoe.mirai.Bot
import net.mamoe.mirai.alsoLogin
import net.mamoe.mirai.event.subscribeMessages
suspend fun main() {
val qqId = 10000L//Bot的QQ号需为Long类型在结尾处添加大写L
val password = "your_password"//Bot的密码
val miraiBot = Bot(qqId, password).alsoLogin()//新建Bot并登陆
miraiBot.subscribeMessages {
"你好" reply "你好!"
case("at me") {
reply(sender.at() + " 给爷爬 ")
}
(contains("舔") or contains("刘老板")) {
"刘老板太强了".reply()
}
}
miraiBot.join()
}
```
- 单击编辑器内第8行(```fun main```)左侧的run按钮(绿色三角)等待MiraiBot成功登录。
- 本例的功能中在任意群内任意成员发送包含“舔”字或“刘老板”字样的消息MiraiBot会回复“刘老板太强了”