mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 08:50:15 +08:00
Better
This commit is contained in:
parent
a0843c1da5
commit
cdd3053e16
@ -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会回复“刘老板太强了”
|
||||
|
Loading…
Reference in New Issue
Block a user