Skip to content

Conversation

Paillat-dev
Copy link
Member

Summary

Allows usage of functions with any number of optional parameters as autocomplete. This allows by extent the usage of partials and similar as autocomplete.

Fixes #2668
Superseeds #2669

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@pycord-app
Copy link

pycord-app bot commented Sep 5, 2025

Thanks for opening this pull request!
Please make sure you have read the Contributing Guidelines and Code of Conduct.

This pull request can be checked-out with:

git fetch origin pull/2914/head:pr-2914
git checkout pr-2914

This pull request can be installed with:

pip install git+https://github.com/Pycord-Development/pycord@refs/pull/2914/head

@Paillat-dev Paillat-dev added on hold hold: testing This pull request requires further testing labels Sep 5, 2025
@Paillat-dev Paillat-dev linked an issue Sep 5, 2025 that may be closed by this pull request
3 tasks
@Paillat-dev Paillat-dev removed on hold hold: testing This pull request requires further testing labels Sep 5, 2025
@Paillat-dev
Copy link
Member Author

Paillat-dev commented Sep 5, 2025

Ok this is kind of spaghetti code, but I mean it works... In next autocompletes should probably be made into classes and it should make most of this mess clearer

Soheab
Soheab previously approved these changes Sep 16, 2025
Copy link
Contributor

@Copilot 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 adds support for using functools.partial and functions returning awaitables as autocomplete handlers for Discord application commands. The key enhancement is making the autocomplete system more flexible by allowing functions with optional parameters and improving the detection of async behavior.

  • Enhanced autocomplete function signature detection to support functions with optional parameters
  • Improved async handling by checking for awaitable results instead of just coroutine functions
  • Added example demonstrating the use of functools.partial for autocomplete

Reviewed Changes

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

File Description
examples/app_commands/slash_autocomplete.py Added example demonstrating functools.partial usage with autocomplete
discord/commands/options.py Enhanced type annotations and added property-based autocomplete with signature analysis
discord/commands/core.py Updated autocomplete invocation to use pre-computed method detection and improved async handling
CHANGELOG.md Added changelog entry documenting the new functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member Author

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

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

.

Signed-off-by: Paillat <jeremiecotti@ik.me>
Signed-off-by: Paillat <paillat@pycord.dev>
@Paillat-dev Paillat-dev requested a review from Soheab September 16, 2025 12:27
Signed-off-by: Paillat <jeremiecotti@ik.me>
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.

Async staticmethod cannot be use as autocomplete (Somehow) Allow autocomplete methods to accept arguments
2 participants