Skip to content
This repository was archived by the owner on Jun 12, 2019. It is now read-only.
Tnze edited this page Feb 2, 2019 · 3 revisions

To send chat message, simply call func (g *Game) Chat(msg string) error, but don't send a msg too long (longer than 256).

Here is a example to send a serious of "emmm".

package main

import (
	"fmt"
	bot "github.com/Tnze/gomcbot"
	"time"
)

func main() {
	p := bot.Auth{Name: "Steve"}

	g, err := p.JoinServer("localhost", 25565)
	if err != nil {
		panic(err)
	}

	events := g.GetEvents()
	go g.HandleGame()

	for e := range events {
		switch e {
		case bot.PlayerSpawnEvent:
			// only send chat messages after you spawn! emmmmmm
			go sendemmm(g)
		}
	}
}

func sendemmm(g *bot.Game) {
	msg := "em"
	for i := 0; i < 20; i++ {
		msg += "m"

		err := g.Chat(msg)
		if err != nil {
			return
		}
		time.Sleep(time.Second)
	}
}

Clone this wiki locally