#Get Current Autocomplete Field input
1 messages · Page 1 of 1 (latest)
public class EmbedNameAutocompleteHandler : AutocompleteHandler
{
public override async Task<AutocompletionResult> GenerateSuggestionsAsync(
IInteractionContext context,
IAutocompleteInteraction autocompleteInteraction,
IParameterInfo parameter,
IServiceProvider services)
{
using var scope = services.CreateGuildScope(context.Guild);
var value = autocompleteInteraction.GetCurrentParameterValue<string>(parameter);
Yes I figured it out eventually
But there is 1 more thing I need to know.
How can I get the value of the previous autocomplete field
Uhh dunno that one
But this is the extension method for the above code
public static class IAutocompleteInteractionExtensions
{
public static object GetCurrentParameterValue(this IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameterInfo)
{
return autocompleteInteraction.Data.Options.First(p => p.Name == parameterInfo.Name).Value;
}
public static T GetCurrentParameterValue<T>(this IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameterInfo)
{
return (T)GetCurrentParameterValue(autocompleteInteraction, parameterInfo);
}
}
For anyone intrested later
I found it by doing autoCompleteInteraction.Data.Current.Value
Or autoCompleteInteraction.Current.Data.Value
One of those
I think you always get the current, so you have to store it if you need it later