Skip to content

Improve simultaneous choices and autocomplete handling#342

Merged
KubaZ2 merged 11 commits intoalphafrom
improve/simultaneous-choices-and-autocomplete-handling
May 8, 2026
Merged

Improve simultaneous choices and autocomplete handling#342
KubaZ2 merged 11 commits intoalphafrom
improve/simultaneous-choices-and-autocomplete-handling

Conversation

@KubaZ2
Copy link
Copy Markdown
Member

@KubaZ2 KubaZ2 commented May 7, 2026

Fixes #341

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

The documentation preview is available at https://preview.netcord.dev/342.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SlashCommandParameter initialization to prioritize explicitly specified AutocompleteProviderType over 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.

Comment thread NetCord.Services/ApplicationCommands/SlashCommandParameter.cs
Comment thread Tests/NetCord.Test/ApplicationCommands/Commands.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread NetCord.Services/ApplicationCommands/SlashCommandParameter.cs
Comment thread Tests/NetCord.Test/ApplicationCommands/Commands.cs Outdated
@AraHaan
Copy link
Copy Markdown

AraHaan commented May 7, 2026

Lmk when this is ready for merge.

@AraHaan
Copy link
Copy Markdown

AraHaan commented May 7, 2026

I see that there is a new test failure now.

@KubaZ2
Copy link
Copy Markdown
Member Author

KubaZ2 commented May 7, 2026

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 InvalidOperationException instead of InvalidDefinitionException and there is no easy way to change that.

KubaZ2 added 2 commits May 8, 2026 13:09
…make autocomplete not being supported throw instead of being ignored
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}'.");

Comment thread NetCord.Services/ApplicationCommands/SubSlashCommandGroupInfo.cs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • GetMemberName returns only member.Name when DeclaringType is null (e.g., for top-level Type instances), which drops the namespace and makes InvalidDefinitionException messages less actionable. Consider special-casing Type to use type.FullName (fallback to type.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}";
    }

Comment thread Tests/ServicesTest/ChoicesAndAutocompleteTests.cs
Comment thread Tests/ServicesTest/ChoicesAndAutocompleteTests.cs
Comment thread Tests/ServicesTest/ChoicesAndAutocompleteTests.cs
Comment thread NetCord.Services/ApplicationCommands/ApplicationCommandService.cs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@KubaZ2 KubaZ2 marked this pull request as ready for review May 8, 2026 13:14
@KubaZ2 KubaZ2 merged commit 84fad56 into alpha May 8, 2026
1 check passed
@KubaZ2 KubaZ2 deleted the improve/simultaneous-choices-and-autocomplete-handling branch May 8, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When making an Autocomplete provider for an enum it never gets run at all.

3 participants