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,24 +72,20 @@ 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退出
coroutineScope() {
launch {
val qqId = 10000L//Bot的QQ号需为Long类型在结尾处添加大写L val qqId = 10000L//Bot的QQ号需为Long类型在结尾处添加大写L
val password = "your_password"//Bot的密码 val password = "your_password"//Bot的密码
val miraiBot = Bot(qqId, password).alsoLogin()//新建Bot并登陆 val miraiBot = Bot(qqId, password).alsoLogin()//新建Bot并登陆
miraiBot.subscribeMessages { miraiBot.subscribeMessages {
"你好" reply "你好!" "你好" reply "你好!"
"profile" reply { sender.queryProfile() }
case("at me") { case("at me") {
reply(sender.at() + " 给爷爬 ") reply(sender.at() + " 给爷爬 ")
} }
@ -99,11 +95,8 @@ JDK要求8以上
} }
} }
miraiBot.join() miraiBot.join()
} }
} ```
}
}
```
- 单击编辑器内第8行(```fun main```)左侧的run按钮(绿色三角)等待MiraiBot成功登录。 - 单击编辑器内第8行(```fun main```)左侧的run按钮(绿色三角)等待MiraiBot成功登录。
- 本例的功能中在任意群内任意成员发送包含“舔”字或“刘老板”字样的消息MiraiBot会回复“刘老板太强了” - 本例的功能中在任意群内任意成员发送包含“舔”字或“刘老板”字样的消息MiraiBot会回复“刘老板太强了”