Skip to content

Commit 9d431e6

Browse files
authored
Merge pull request #174 from disgoorg/rework-interaction-option-handling
Rework interaction option handling and resume fixes
2 parents 0285834 + 96b9d71 commit 9d431e6

8 files changed

+256
-832
lines changed

_examples/test/commands.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ var commands = []discord.ApplicationCommandCreate{
1515
CommandName: "test",
1616
Description: "test",
1717
},
18+
discord.SlashCommandCreate{
19+
CommandName: "test2",
20+
Description: "test2",
21+
Options: []discord.ApplicationCommandOption{
22+
discord.ApplicationCommandOptionInt{
23+
OptionName: "number",
24+
Description: "some number",
25+
Required: true,
26+
},
27+
discord.ApplicationCommandOptionInt{
28+
OptionName: "message",
29+
Description: "What to say",
30+
Required: true,
31+
Autocomplete: true,
32+
},
33+
},
34+
},
1835
discord.SlashCommandCreate{
1936
CommandName: "say",
2037
Description: "says what you say",

_examples/test/listeners.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var listener = &events.ListenerAdapter{
1616
OnApplicationCommandInteraction: applicationCommandListener,
1717
OnComponentInteraction: componentListener,
1818
OnModalSubmit: modalListener,
19+
OnAutocompleteInteraction: autocompleteListener,
1920
}
2021

2122
func modalListener(event *events.ModalSubmitInteractionCreate) {
@@ -131,6 +132,24 @@ func applicationCommandListener(event *events.ApplicationCommandInteractionCreat
131132
}
132133
}
133134

135+
func autocompleteListener(event *events.AutocompleteInteractionCreate) {
136+
switch event.Data.CommandName {
137+
case "test2":
138+
if err := event.Result([]discord.AutocompleteChoice{
139+
discord.AutocompleteChoiceInt{
140+
Name: "test1",
141+
Value: 1,
142+
},
143+
discord.AutocompleteChoiceInt{
144+
Name: "test2",
145+
Value: 2,
146+
},
147+
}); err != nil {
148+
event.Client().Logger().Error("error on sending response: ", err)
149+
}
150+
}
151+
}
152+
134153
func messageListener(event *events.GuildMessageCreate) {
135154
if event.Message.Author.Bot {
136155
return

0 commit comments

Comments
 (0)