1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 09:12:53 +00:00
arikawa/arikawa_example_test.go
diamondburned 5e0d1cfe4a
*: Move state example to root package
Also updated it to use Connect instead of Open and Close.
2023-08-24 22:39:42 -07:00

27 lines
580 B
Go

package arikawa_test
import (
"context"
"log"
"os"
"os/signal"
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/state"
)
func Example() {
s := state.New("Bot " + os.Getenv("DISCORD_TOKEN"))
s.AddIntents(gateway.IntentGuilds | gateway.IntentGuildMessages)
s.AddHandler(func(m *gateway.MessageCreateEvent) {
log.Printf("%s: %s", m.Author.Username, m.Content)
})
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
if err := s.Connect(ctx); err != nil {
log.Println("cannot open:", err)
}
}