Start a basic connection to Discord.

pull/1/head
pocketjawa 2019-04-27 00:12:46 -04:00
parent 8cf6c3b68b
commit 8afc7ffa58
1 changed files with 35 additions and 0 deletions

View File

@ -2,8 +2,43 @@ package main
import (
"fmt"
"flag"
"log"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
)
func main () {
fmt.Println("butts!")
var Session, _ = discordgo.New()
func init(){
Session.Token = os.Getenv("DISCORD_TOKEN")
if Session.Token == "" {
flag.StringVar(&Session.Token, "t", "", "Discord Authentication 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.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
Session.Close()
}