Setup basic discord session

This commit is contained in:
Piper Pentagram 2024-11-06 11:34:45 -08:00
parent 571aa3650e
commit 4b62347d5d
5 changed files with 80 additions and 0 deletions

45
main.go Normal file
View file

@ -0,0 +1,45 @@
package main
import (
"flag"
"log"
"os"
"os/signal"
"github.com/bwmarrin/discordgo"
)
var (
Token = flag.String("token", "", "Bot authentication token")
App = flag.String("app", "", "Application ID")
Guild = flag.String("guild", "", "Guild ID") // Do we want it to be tied to one server?
)
func main() {
flag.Parse()
if *App == "" {
log.Fatal("application id is not set")
}
startBot()
}
func startBot() {
session, _ := discordgo.New("Bot " + *Token)
err := session.Open()
if err != nil {
log.Fatalf("could not open session: %s", err)
}
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, os.Interrupt)
<-sigch
log.Printf("shutting down gracefully...")
err = session.Close()
if err != nil {
log.Printf("could not close session gracefully: %s", err)
}
}