diff --git a/main.go b/main.go index 02125c5..f76494e 100644 --- a/main.go +++ b/main.go @@ -753,6 +753,18 @@ var ( } ) +func registerCommandsForGuild(s *discordgo.Session, guildID string) { + appID := s.State.User.ID + cmds, err := s.ApplicationCommandBulkOverwrite(appID, guildID, slashCommands) + if err != nil { + log.Printf("BulkOverwrite %s failed: %v", guildID, err) + return + } + cfgMu.Lock() + createdCmds[guildID] = cmds + cfgMu.Unlock() +} + // ===== main: Multi-Guild, pro Guild registrieren ===== func main() { token := os.Getenv("DISCORD_TOKEN") @@ -774,6 +786,14 @@ func main() { s.AddHandler(onVoiceStateUpdate) s.AddHandler(onGuildCreate) + s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) { + for _, g := range s.State.Guilds { + registerCommandsForGuild(s, g.ID) + } + }) + s.AddHandler(func(s *discordgo.Session, g *discordgo.GuildCreate) { + registerCommandsForGuild(s, g.ID) + }) s.AddHandler(onInteractionCreate("")) s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) { log.Printf("Eingeloggt als %s", r.User.Username)