package main import ( "flag" "fmt" "github.com/bwmarrin/discordgo" "log" "os" "os/signal" "syscall" ) var Session, _ = discordgo.New() var testPtr = flag.Bool("test", false, "Test mode") var bot_token string func init() { if os.Getenv("DISCORD_TOKEN") != "" { Session.Token = "Bot " + os.Getenv("DISCORD_TOKEN") } else { flag.StringVar(&bot_token, "t", "", "Discord Authentication Token") flag.Parse() Session.Token = "Bot " + bot_token } } func main() { var err error fmt.Println("butts!") flag.Parse() if Session.Token == "" { log.Println("You must provide a Discord auth token!") return } //Open a connection to Discord err = Session.Open() if err != nil { log.Printf("Error opening connection to Discord, %s\n", err) os.Exit(1) } //Wait for a CTRL-C log.Printf("Now running. Press CTRL-C to exit.") if *testPtr == true { log.Printf("Test successful! Now quiting.") Session.Close() os.Exit(0) } sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) <-sc Session.Close() }