Skip to content

Commit 6638c50

Browse files
committed
fix: bring back component & modal register methods
1 parent 839a245 commit 6638c50

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

client-registry.go

+35
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,41 @@ func (client *Client) RegisterSubCommand(subCommand Command, rootCommandName str
4141
return nil
4242
}
4343

44+
// Bind function to all components with matching custom ids. App will automatically run bound function whenever receiving component interaction with matching custom id.
45+
func (client *Client) RegisterComponent(customIDs []string, fn func(*ComponentInteraction)) error {
46+
if client.State() != INIT_STATE {
47+
return errors.New("client is no longer in initialization state (avoid editing client's internals after it launches)")
48+
}
49+
50+
for _, ID := range customIDs {
51+
_, exists := client.components[ID]
52+
if exists {
53+
return errors.New("client already has registered \"" + ID + "\" component (custom id already in use)")
54+
}
55+
}
56+
57+
for _, ID := range customIDs {
58+
client.components[ID] = fn
59+
}
60+
61+
return nil
62+
}
63+
64+
// Bind function to modal with matching custom id. App will automatically run bound function whenever receiving modal interaction with matching custom id.
65+
func (client *Client) RegisterModal(customID string, fn func(*ModalInteraction)) error {
66+
if client.State() != INIT_STATE {
67+
return errors.New("client is no longer in initialization state (avoid editing client's internals after it launches)")
68+
}
69+
70+
_, exists := client.modals[customID]
71+
if exists {
72+
return errors.New("client already has registered \"" + customID + "\" modal (custom id already in use)")
73+
}
74+
75+
client.modals[customID] = fn
76+
return nil
77+
}
78+
4479
// Sync currently cached slash commands to discord API. By default it'll try to make (bulk) global update (limit 100 updates per day), provide array with guild id snowflakes to update data only for specific guilds.
4580
// You can also add second param -> slice with all command names you want to update (whitelist). There's also third, boolean param that when = true will reverse wishlist to work as blacklist.
4681
func (client *Client) SyncCommands(guildIDs []Snowflake, whitelist []string, switchMode bool) error {

0 commit comments

Comments
 (0)