TerraOceanPlugin/GoBot/discord/discord.go

38 lines
663 B
Go

2019-10-12 09:45:43 +07:00
package discord
import (
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
"TerraOceanBot/discord/modules"
)
2019-10-12 15:49:28 +07:00
func StartBot(token string, kill chan bool) {
2019-10-12 09:45:43 +07:00
dg, err := discordgo.New("Bot " + strings.TrimSpace(token))
if err != nil {
panic(err)
}
dg.AddHandler(ProcessCommand)
dg.AddHandler(ProcessVote)
dg.AddHandler(modules.CheckForVote)
dg.AddHandler(modules.CheckForTrustUpdate)
dg.AddHandler(modules.CheckForInvite)
if err := dg.Open(); err != nil {
panic(err)
}
fmt.Println("Bot is now running. Press CTRL-C to exit.")
go modules.ListenToVoteFinishes(dg)
2019-10-12 15:49:28 +07:00
<-kill
2019-10-12 09:45:43 +07:00
dg.Close()
fmt.Println("Discordgo exited successfully.")
2019-10-12 15:49:28 +07:00
<-kill
2019-10-12 09:45:43 +07:00
}