Added a purge for old commands and re-adding every start
This commit is contained in:
parent
69b76bd792
commit
82c62658bb
1 changed files with 17 additions and 1 deletions
18
main.go
18
main.go
|
@ -127,7 +127,23 @@ func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerCommands(s *discordgo.Session) {
|
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))
|
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
|
||||||
for i, v := range commands {
|
for i, v := range commands {
|
||||||
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, "", v)
|
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, "", v)
|
||||||
|
|
Loading…
Add table
Reference in a new issue