-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.go
43 lines (33 loc) · 1009 Bytes
/
bot.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 (
"log"
"fmt"
"github.com/bwmarrin/discordgo"
)
var BotID string
var DGSession *discordgo.Session
func BotRun() {
DGSession, err := discordgo.New(BotToken)
if err != nil { panic(err.Error()) }
DGSession.Identify.Intents = discordgo.IntentsAll
DGSession.AddHandler(MessageHandler);
DGSession.AddHandler(SlashCommandHandler);
DGSession.AddHandler(JoinHandler);
/* grab the bot user's id */
botUser, err := DGSession.User("@me")
if err != nil { log.Panic(err.Error()) }
BotID = botUser.ID
err = DGSession.Open()
if err != nil { log.Panic(err.Error()) }
fmt.Println("Bot is now running...")
/* initialize slash commands */
for _, c := range SlashCommands {
_, err := DGSession.ApplicationCommandCreate(DGSession.State.User.ID, CommandGuildID, c)
if err != nil {
log.Printf("Failed to create slash command: %v", c.Name, err)
}
}
}
func BotStop() {
DGSession.Close()
}