-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord.go
40 lines (33 loc) · 934 Bytes
/
discord.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
package main
import (
"log"
"os"
"github.com/bwmarrin/discordgo"
)
var DISCORD_TOKEN = os.Getenv("DISCORD_TOKEN")
var DISCORD_CHANNEL = os.Getenv("DISCORD_CHANNEL")
// Variables used for command line parameters
type DiscordBot struct {
Session *discordgo.Session
Token string
Notified map[int32]bool
Startup chan string
}
func (discord *DiscordBot) NewDiscordBot() {
// Create a new Discord session using the provided bot token.
dg, err := discordgo.New("Bot " + discord.Token)
if err != nil {
log.Println("error creating Discord session,", err)
return
}
// In this example, we only care about receiving message events.
dg.Identify.Intents = discordgo.IntentsGuildMessages
// Open a websocket connection to Discord and begin listening.
err = dg.Open()
if err != nil {
log.Println("error opening connection,", err)
return
}
discord.Session = dg
discord.Startup <- "[DEBUG] Discord bot running"
}