-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (35 loc) · 1015 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
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/aid95/zaksim-discord-bot/bot/handlers"
"github.com/aid95/zaksim-discord-bot/db"
"github.com/aid95/zaksim-discord-bot/utils/gen/message"
"github.com/bwmarrin/discordgo"
)
func main() {
// Database 연결.
if err := db.Open(); err != nil {
log.Fatal(message.Error("Failed to connect to database. "), err)
}
defer db.Close()
// DiscordGo를 위한 준비 및 실행
dg, err := discordgo.New("Bot " + os.Getenv("DISCORD_BOT_TOKEN"))
if err != nil {
log.Fatal(message.Error("Failed creating Discord session. "), err)
}
defer dg.Close()
//-- 봇 핸들러 등록
dg.AddHandler(handlers.CommuteHandler)
//-- 봇 연결
if err = dg.Open(); err != nil {
log.Fatal(message.Error("Failed opening connection. "), err)
}
fmt.Println(message.Info("Zaksim bot is 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
}