1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-08-31 02:45:18 +00:00
arikawa/gateway/gateway_example_test.go
2023-08-04 14:24:50 -07:00

32 lines
621 B
Go

package gateway_test
import (
"context"
"log"
"os"
"os/signal"
"libdb.so/arikawa/v4/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)
}
}
}