-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (36 loc) · 825 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"os"
"github.com/bwmarrin/discordgo"
"github.com/subosito/gotenv"
)
// BotID globally stores the bot's ID
var BotID string
func init() { gotenv.Load() }
func main() {
// Create discord session
dg, err := discordgo.New("Bot " + os.Getenv("TOKEN"))
if err != nil {
fmt.Println("Error while creating discord session:\n", err)
return
}
// Get user info for the bot
u, err := dg.User("@me")
if err != nil {
fmt.Println("Error while getting user info:\n", err)
return
}
// Get the id of the bot
BotID = u.ID
dg.AddHandler(MessageHandler)
// Open the websocket and begin listening
err = dg.Open()
if err != nil {
fmt.Println("Error while openning the websocket:\n", err)
return
}
fmt.Println("Discord Bot is running!")
defer dg.Close()
<-make(chan struct{})
}