Skip to content

Commit

Permalink
Moved command handler to ready function
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTipo01 committed Mar 27, 2021
1 parent c00841c commit c9048eb
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,6 @@ func main() {
return
}

// Checks for unused commands and deletes them
if cmds, err := dg.ApplicationCommands(dg.State.User.ID, ""); err == nil {
for _, c := range cmds {
if commandHandlers[c.Name] == nil {
_ = dg.ApplicationCommandDelete(dg.State.User.ID, "", c.ID)
lit.Info("Deleted unused command %s", c.Name)
}
}
}

// And add commands used
lit.Info("Adding used commands...")
for _, v := range commands {
_, err := dg.ApplicationCommandCreate(dg.State.User.ID, "", v)
if err != nil {
lit.Error("Cannot create '%v' command: %v", v.Name, err)
}
}
lit.Info("Commands added!")

// Wait here until CTRL-C or other term signal is received.
lit.Info("roberto is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
Expand All @@ -160,9 +140,26 @@ func ready(s *discordgo.Session, _ *discordgo.Ready) {
if err != nil {
lit.Error("Can't set status, %s", err)
}

// Checks for unused commands and deletes them
if cmds, err := s.ApplicationCommands(s.State.User.ID, ""); err == nil {
for _, c := range cmds {
if commandHandlers[c.Name] == nil {
_ = s.ApplicationCommandDelete(s.State.User.ID, "", c.ID)
lit.Info("Deleted unused command %s", c.Name)
}
}
}

// And add commands used
for _, v := range commands {
_, err := s.ApplicationCommandCreate(s.State.User.ID, "", v)
if err != nil {
lit.Error("Cannot create '%v' command: %v", v.Name, err)
}
}
}

func guildCreate(_ *discordgo.Session, e *discordgo.GuildCreate) {
initializeServer(e.Guild.ID)
}

0 comments on commit c9048eb

Please sign in to comment.