Added a purge for old commands and re-adding every start

This commit is contained in:
Atridad Lahiji 2024-11-05 16:42:44 -06:00
parent 69b76bd792
commit 82c62658bb
Signed by: atridad
SSH key fingerprint: SHA256:LGomp8Opq0jz+7kbwNcdfTcuaLRb5Nh0k5AchDDb438

18
main.go
View file

@ -127,7 +127,23 @@ func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
}
func registerCommands(s *discordgo.Session) {
log.Println("Registering commands...")
// First, delete all existing commands
log.Println("Deleting existing commands...")
existingCommands, err := s.ApplicationCommands(s.State.User.ID, "")
if err != nil {
log.Printf("Error fetching existing commands: %v", err)
}
for _, cmd := range existingCommands {
err := s.ApplicationCommandDelete(s.State.User.ID, "", cmd.ID)
if err != nil {
log.Printf("Error deleting command %s: %v", cmd.Name, err)
}
}
// Then register the new commands
log.Println("Registering new commands...")
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
for i, v := range commands {
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, "", v)