Browse Source

Improved example in int.framework intro

pull/2288/head
Misha133 3 years ago
parent
commit
999f8e0fce
1 changed files with 12 additions and 4 deletions
  1. +12
    -4
      docs/guides/int_framework/samples/intro/autocomplete.cs

+ 12
- 4
docs/guides/int_framework/samples/intro/autocomplete.cs View File

@@ -1,9 +1,17 @@
[AutocompleteCommand("parameter_name", "command_name")]
public async Task Autocomplete()
{
IEnumerable<AutocompleteResult> results;
IEnumerable<AutocompleteResult> results = new[]
{
new AutocompleteResult("Name1", "value1"),
new AutocompleteResult("Name2", "value2")
};

...

await (Context.Interaction as SocketAutocompleteInteraction).RespondAsync(results);
// max - 25 suggestions at a time
await (Context.Interaction as SocketAutocompleteInteraction).RespondAsync(results.Take(25));
}

// you need to add `Autocomplete` attribute before parameter to add autocompletion to it
[SlashCommand("command_name", "command_description")]
public async Task ExampleCommand([Summary("parameter_name"), Autocomplete] string parameterWithAutocompletion)
=> await RespondAsync($"Your choice: {parameterWithAutocompletion}");

Loading…
Cancel
Save