-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 1.07 KB
/
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
package main
import (
"github.com/bwmarrin/discordgo"
"github.com/MikeModder/anpan"
)
type Command interface {
Name() string
Execute(session *discordgo.Session, msg *discordgo.MessageCreate)
}
var commandMap = make(map[string]Command)
func main() {
dg, _ := discordgo.New("Bot " + "your-token-goes-here")
dg.AddHandler(messageCreate)
dg.Open()
defer dg.Close()
loadCommands()
// Keep the program running until interrupted
select {}
}
func loadCommands(commands) {
log.Println("This is a simple log message.")
files, _ := ioutil.ReadDir("./commands")
for _, f := range files {
if strings.HasSuffix(f.Name(), ".go") {
// Assuming each file only contains one command
commandName := strings.TrimSuffix(f.Name(), ".go")
switch commandName {
case "ping":
commandMap[commandName] = &commands.PingCommand{}
// Add cases for other commands here
}
}
}
}
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
if command, ok := commandMap[m.Content]; ok {
command.Execute(s, m)
}
}