TerraOceanPlugin/GoBot/discord/discord.go

42 lines
790 B
Go

package discord
import (
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
"TerraOceanBot/discord/backend"
"TerraOceanBot/discord/modules"
)
func StartBot(token string, kill chan bool) {
dg, err := discordgo.New("Bot " + strings.TrimSpace(token))
if err != nil {
panic(err)
}
dg.AddHandler(ProcessCommand)
dg.AddHandler(ProcessVoiceStateUpdate)
dg.AddHandler(modules.CheckForReact)
dg.AddHandler(modules.CheckForVote)
dg.State.TrackMembers = true
dg.State.TrackVoice = true
if err := dg.Open(); err != nil {
panic(err)
}
fmt.Println("Bot is now running. Press CTRL-C to exit.")
modules.GenerateHelpEmbed()
go modules.ListenToVoteFinishes(dg)
go backend.UpdateVoiceChannelState(dg)
<-kill
dg.Close()
fmt.Println("Discordgo exited successfully.")
<-kill
}