1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-01 12:34:28 +00:00
arikawa/0-examples/commands-minimal/main.go

35 lines
927 B
Go
Raw Normal View History

package main
import (
"context"
"log"
"os"
"github.com/diamondburned/arikawa/v3/api"
"github.com/diamondburned/arikawa/v3/api/cmdroute"
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/state"
"github.com/diamondburned/arikawa/v3/utils/json/option"
)
var commands = []api.CreateCommandData{{Name: "ping", Description: "Ping!"}}
func main() {
r := cmdroute.NewRouter()
r.AddFunc("ping", func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
return &api.InteractionResponseData{Content: option.NewNullableString("Pong!")}
})
s := state.New("Bot " + os.Getenv("BOT_TOKEN"))
s.AddInteractionHandler(r)
s.AddIntents(gateway.IntentGuilds)
if err := cmdroute.OverwriteCommands(s, commands); err != nil {
log.Fatalln("cannot update commands:", err)
}
if err := s.Connect(context.TODO()); err != nil {
log.Println("cannot connect:", err)
}
}