Skip to content

Commit 3dbf6a6

Browse files
authored
handler add helper to sync commands for guilds or globally
1 parent 2fc89bc commit 3dbf6a6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

handler/handler.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,29 @@ import (
2121
"errors"
2222
"strings"
2323

24+
"github.com/disgoorg/snowflake/v2"
25+
26+
"github.com/disgoorg/disgo/bot"
2427
"github.com/disgoorg/disgo/discord"
2528
"github.com/disgoorg/disgo/events"
29+
"github.com/disgoorg/disgo/rest"
2630
)
2731

32+
// SyncCommands sets the given commands for the given guilds or globally if no guildIDs are empty. It will return on the first error for multiple guilds.
33+
func SyncCommands(client bot.Client, commands []discord.ApplicationCommandCreate, guildIDs []snowflake.ID, opts ...rest.RequestOpt) error {
34+
if len(guildIDs) == 0 {
35+
_, err := client.Rest().SetGlobalCommands(client.ApplicationID(), commands, opts...)
36+
return err
37+
}
38+
for _, guildID := range guildIDs {
39+
_, err := client.Rest().SetGuildCommands(client.ApplicationID(), guildID, commands, opts...)
40+
if err != nil {
41+
return err
42+
}
43+
}
44+
return nil
45+
}
46+
2847
type handlerHolder[T any] struct {
2948
pattern string
3049
handler T

0 commit comments

Comments
 (0)