2023-08-25 05:39:41 +00:00
|
|
|
package arikawa_test
|
2021-09-28 20:19:04 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2023-08-25 05:39:41 +00:00
|
|
|
if err := s.Connect(ctx); err != nil {
|
2021-09-28 20:19:04 +00:00
|
|
|
log.Println("cannot open:", err)
|
|
|
|
}
|
|
|
|
}
|