-
Notifications
You must be signed in to change notification settings - Fork 10
/
discord.go
48 lines (40 loc) · 1.25 KB
/
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
41
42
43
44
45
46
47
48
package conservator
import (
"github.com/bwmarrin/discordgo"
)
var dg *discordgo.Session
func (c *Conservator) setupDiscord() (*discordgo.Session, error) {
d, err := discordgo.New("Bot " + c.discordToken)
if err != nil {
return nil, err
}
d.AddHandler(c.discordMessageCreate)
d.AddHandler(c.discordGuildCreate)
return d, nil
}
func (c *Conservator) discordNewMember(s *discordgo.Session, e *discordgo.GuildMemberAdd) {
// Ignore all messages created by the bot itself
// This isn't required in this specific example but it's a good practice.
if e.Member.User.ID == s.State.User.ID {
return
}
c.handleNewMember(e.Member.User.ID, e.Member.Nick, e.GuildID)
}
func (c *Conservator) discordMessageCreate(s *discordgo.Session, e *discordgo.MessageCreate) {
// Ignore all messages created by the bot itself
// This isn't required in this specific example but it's a good practice.
if e.Author.ID == s.State.User.ID {
return
}
}
func (c *Conservator) discordGuildCreate(s *discordgo.Session, e *discordgo.GuildCreate) {
if e.Guild.Unavailable {
return
}
for _, channel := range e.Guild.Channels {
if channel.ID == e.Guild.ID {
_, _ = s.ChannelMessageSend(channel.ID, "Discord Integration Complete - https://www.evedata.org")
return
}
}
}