-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (43 loc) · 813 Bytes
/
main.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
49
50
51
52
53
54
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
var (
token string = "ODIxMzE0NTg2ODg3MzIzNjQ4.YFB60A.0JuGRgw3J6ayDCwQdb8GGj63vGA"
//BotID is to
BotID string
)
func main() {
dg, err := discordgo.New("Bot " + token)
if err != nil {
fmt.Println(err.Error())
return
}
u, err := dg.User("@me")
if err != nil {
fmt.Println(err.Error())
}
BotID = u.ID
dg.AddHandler(messageHandler)
err = dg.Open()
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println("Bot is running")
<-make(chan struct{})
return
}
func messageHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == BotID {
return
}
if m.Content == "ping" {
_, err := s.ChannelMessageSend(m.ChannelID, "pong")
if err != nil {
fmt.Println(err.Error())
return
}
}
}