Browse Source

Added a method to get a discord session

Thisnthat 5 years ago
parent
commit
f36b51310a
1 changed files with 21 additions and 0 deletions
  1. 21 0
      session.go

+ 21 - 0
session.go

@@ -0,0 +1,21 @@
+package discord
+
+import "github.com/bwmarrin/discordgo"
+
+// GetSession - Get a discord session from the provided token
+func GetSession(token string) (*discordgo.Session, error) {
+	session, err := discordgo.New("Bot " + token)
+
+	// If we can not create the client then just fatal.
+	if err != nil {
+		return nil, err
+	}
+
+	// Open a websocket connection to Discord and begin listening.
+	err = session.Open()
+	if err != nil {
+		return nil, err
+	}
+
+	return session, nil
+}