Improve simultaneous choices and autocomplete handling#342
Conversation
|
The documentation preview is available at https://preview.netcord.dev/342. |
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #341 where an explicitly configured autocomplete provider on an enum slash-command parameter was never invoked because enum parameters defaulted to a built-in choices provider. The update adjusts parameter/provider resolution to ensure autocomplete can be used for enums and enforces the Discord constraint that choices and autocomplete cannot be enabled simultaneously.
Changes:
- Refactors
SlashCommandParameterinitialization to prioritize explicitly specifiedAutocompleteProviderTypeover default enum choices handling. - Adds a guard that throws when both a choices provider and an autocomplete provider are specified for the same parameter.
- Adds a test/repro module demonstrating enum autocomplete usage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Tests/NetCord.Test/ApplicationCommands/Commands.cs | Adds a repro command/module with an enum parameter using AutocompleteProviderType. |
| NetCord.Services/ApplicationCommands/SlashCommandParameter.cs | Refactors provider-selection logic to avoid “choices + autocomplete” conflicts and to allow enum autocomplete. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Lmk when this is ready for merge. |
|
I see that there is a new test failure now. |
Yeah, I was moving code from my laptop. I need to make a big refactor to make it pass. Basically they fail because I throw |
…make autocomplete not being supported throw instead of being ignored
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
NetCord.Services/ApplicationCommands/SlashCommandGroupInfo.cs:45
- This constructor now participates in the autocomplete/definition validation changes, but it still throws InvalidOperationException when no subcommands are found. Elsewhere in ApplicationCommands (e.g., SlashCommandParameter and SubSlashCommandGroupInfo) invalid command definitions now throw InvalidDefinitionException. Consider switching this to InvalidDefinitionException for consistency and so callers can reliably catch definition errors.
if (subCommands.Count == 0)
throw new InvalidOperationException($"No sub commands found in '{type.FullName}'.");
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
NetCord.Services/InvalidDefinitionException.cs:20
GetMemberNamereturns onlymember.NamewhenDeclaringTypeis null (e.g., for top-levelTypeinstances), which drops the namespace and makesInvalidDefinitionExceptionmessages less actionable. Consider special-casingTypeto usetype.FullName(fallback totype.Name) so error output includes the full type name.
private static string GetMemberName(MemberInfo member)
{
var declaringType = member.DeclaringType;
return declaringType is null ? member.Name : $"{declaringType.FullName}.{member.Name}";
}
Fixes #341