1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-11 16:05:00 +00:00
arikawa/gateway/gateway_example_test.go

32 lines
637 B
Go
Raw Normal View History

package gateway_test
import (
"context"
"log"
"os"
"os/signal"
"github.com/diamondburned/arikawa/v3/gateway"
)
func Example() {
token := os.Getenv("BOT_TOKEN")
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
g, err := gateway.NewWithIntents(ctx, token, gateway.IntentGuilds)
if err != nil {
log.Fatalln("failed to initialize gateway:", err)
}
for op := range g.Connect(ctx) {
switch data := op.Data.(type) {
case *gateway.ReadyEvent:
log.Println("logged in as", data.User.Username)
case *gateway.MessageCreateEvent:
log.Println("got message", data.Content)
}
}
}