You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I double checked the docs and couldn't find any useful information.
Verify Issue Source
I verified the issue was caused by Discord.Net.
Check your intents
I double checked that I have the required intents.
Description
When defining a slash command, attributes applied to the parameter are not passed to the Autocomplete Handler.
Steps to Reproduce:
Define a slash command with and apply an attribute to it.
[SlashCommand("test", "Desc")]
public Task Test([CustomAutocomplete("option1", "option2")] string parameter)
Attempt to access the attribute of the parameter within an AutocompleteHandler.
public class CustomAutocompleteAttribute : AutocompleteAttribute
{
internal readonly string[] _options;
public CustomAutocompleteAttribute(params string[] options) : base(typeof(CustomAutocompleteHandler))
{
_options = options;
}
}
public class CustomAutocompleteHandler : AutocompleteHandler
{
public override async Task<AutocompletionResult> GenerateSuggestionsAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, IServiceProvider services)
{
var attribute = (CustomAutocompleteAttribute)parameter.Attributes.Single(a => a is CustomAutocompleteAttribute); //Throws, and Actually parameter.Attributes is empty
var options = attribute._options;
//code
return AutocompletionResult.FromSuccess(/*results*/);
}
}
Based on what I gathered, I've seen only the Optional Attribute to get passed, either when it is explicitly put or when the parameter is defined with a default like string parameter = ""
Version
3.17.0
Working Version
No response
Logs
nothing extra in logs besides the single assertion throwing
Sample
No response
Packages
not applicable
Environment
Windows 10 22H2 x64
.NET 8.0
The text was updated successfully, but these errors were encountered:
Based on further testing I found out that certain attributes and their subtypes don't get passed down to AutocompleteHandler, AutocompleteAttribute being one of them.
To get around this, defining a separate attribute to contain the data works, but I find it inelegant:
[SlashCommand("test", "Desc")]
public Task Test([Autocomplete<CustomAutocompleteHandler>, Custom("option1", "option2")] string parameter)
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
public class CustomAttribute : Attribute
{
internal readonly string[] _options;
public CustomAttribute(params string[] options)
{
_options = options;
}
}
public class CustomAutocompleteHandler : AutocompleteHandler
{
public override async Task<AutocompletionResult> GenerateSuggestionsAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, IServiceProvider services)
{
var attribute = (CustomAttribute)parameter.Attributes.Single(a => a is CustomAttribute);
var options = attribute._options;
//code
return AutocompletionResult.FromSuccess(/*results*/);
}
}
Check The Docs
Verify Issue Source
Check your intents
Description
When defining a slash command, attributes applied to the parameter are not passed to the Autocomplete Handler.
Steps to Reproduce:
Based on what I gathered, I've seen only the Optional Attribute to get passed, either when it is explicitly put or when the parameter is defined with a default like string parameter = ""
Version
3.17.0
Working Version
No response
Logs
nothing extra in logs besides the single assertion throwing
Sample
No response
Packages
not applicable
Environment
The text was updated successfully, but these errors were encountered: