-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddcommands.go
37 lines (30 loc) · 864 Bytes
/
addcommands.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
package main
import (
"fmt"
"issues/command"
"issues/slash"
"log"
"os"
"github.com/bwmarrin/discordgo"
)
var commands = map[string]*slash.Command{
"mark": &command.Mark,
"issue": &command.Issue,
"project": &command.Project,
"list": &command.List,
"registerrole": &command.RegisterRole,
}
var registeredCommands = make([]*discordgo.ApplicationCommand, 0)
func registerCommands(session *discordgo.Session) error {
log.Println("Adding commands...")
guildid := os.Getenv("DISCORD_GUILD_ID")
for _, c := range commands {
cmd, err := session.ApplicationCommandCreate(session.State.User.ID, guildid, &c.ApplicationCommand)
if err != nil {
return fmt.Errorf("Cannot create %s due to %s", c.Name, err.Error())
}
registeredCommands = append(registeredCommands, cmd)
}
log.Println("Added commands")
return nil
}