34 lines
861 B
Go
34 lines
861 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
func registerCommands() {
|
|
log.Printf("Registering commands...")
|
|
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
|
|
for i, v := range commands {
|
|
cmd, err := discord.ApplicationCommandCreate(discord.State.User.ID, "", v)
|
|
if err != nil {
|
|
log.Panicf("Cannot create '%v' command: %v", v.Name, err)
|
|
}
|
|
registeredCommands[i] = cmd
|
|
}
|
|
}
|
|
|
|
func cleanCommands() {
|
|
log.Println("Cleaning commands...")
|
|
registeredCommands, err := discord.ApplicationCommands(discord.State.User.ID, "")
|
|
if err != nil {
|
|
log.Fatalf("Could not fetch registered commands: %v", err)
|
|
}
|
|
for _, v := range registeredCommands {
|
|
err := discord.ApplicationCommandDelete(discord.State.User.ID, "", v.ID)
|
|
if err != nil {
|
|
log.Panicf("Cannot delete '%v' command: %v", v.Name, err)
|
|
}
|
|
}
|
|
}
|