学点go
一分钟让机器人说helloworld
做这些的前置条件是应该先把go-cqhttp运行并且已经登录了botqq的
创建 一个 main.go 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| package main
import ( zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/driver" "github.com/wdvxdr1123/ZeroBot/message" )
func init() { engine := zero.New() engine.OnFullMatch("hello").Handle(func(ctx *zero.Ctx) { ctx.SendChain(message.Text("hello world!")) }) }
func main(){ zero.RunAndBlock(zero.Config{ NickName: []string{"bot"}, CommandPrefix: "/", SuperUsers: []int64{123456(这里是主人qq号)}, Driver: []zero.Driver{ driver.NewWebSocketClient("ws://127.0.0.1:6700/", ""), }, }, nil) }
|
然后终端输入 go mod init hello
然后就创建了一个go.mod文件
下一步终端输入 go mod tidy
导入一些插件和依赖
之后终端输入 go run (双引号)“路径/main.go”(双引号)