diff --git a/client/discord/discord.go b/client/discord/discord.go index d1dbbf4..7cdc5e9 100644 --- a/client/discord/discord.go +++ b/client/discord/discord.go @@ -196,6 +196,22 @@ func updateForum(conf *domain.Config, s *discordgo.Session) ([]discordgo.ForumTa } func commandRegistration(s *discordgo.Session, commands []discordgo.ApplicationCommand) []*discordgo.ApplicationCommand { + oldCommands, err := s.ApplicationCommands(s.State.User.ID, s.State.Application.GuildID) + if err != nil { + log.Panicf("Cannot get old commands: %v", err) + } + + var removedCommands []string + for _, cmd := range oldCommands { + err := s.ApplicationCommandDelete(s.State.User.ID, s.State.Application.GuildID, cmd.ID) + if err != nil { + log.Printf("commands removed: %v", removedCommands) + log.Panicf("removing old comands failed with %s command, err: %v", cmd.Name, err) + } + removedCommands = append(removedCommands, cmd.Name) + } + log.Printf("commands removed: %v", removedCommands) + log.Println("Adding commands...") var cmds []*discordgo.ApplicationCommand for _, cmd := range commands {