#Get Current Autocomplete Field input

1 messages · Page 1 of 1 (latest)

elfin musk
#

Is there a way i can get the current user input to an Autocompletion interaction?

public override async Task<AutocompletionResult> GenerateSuggestionsAsync(IInteractionContext context, IAutocompleteInteraction autoCompleteInteraction, IParameterInfo parameter, IServiceProvider services) {...}
lime gorge
# elfin musk Is there a way i can get the current user input to an Autocompletion interaction...
    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);
elfin musk
#

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

lime gorge
#

Uhh dunno that one

elfin musk
#

I had it working once

#

But I don't think I can find the code anymore

lime gorge
#

But this is the extension method for the above code

lime gorge
# lime gorge ``` public class EmbedNameAutocompleteHandler : AutocompleteHandler { ...
    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

elfin musk
#

I found it by doing autoCompleteInteraction.Data.Current.Value

#

Or autoCompleteInteraction.Current.Data.Value
One of those

lime gorge