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