Skip to content

Conversation

valzargaming
Copy link
Member

This pull request refactors how Discord interactions are handled, with a focus on improving type safety and clarity for application commands and autocomplete interactions. The main changes include updating type hints and conditional logic to distinguish between ApplicationCommand and ApplicationCommandAutocomplete instances, and simplifying checks for interaction properties.

Type safety and interaction handling improvements:

  • Updated type hints in the execute and checkCommand methods to accept both ApplicationCommand and ApplicationCommandAutocomplete instances, improving clarity and correctness in method signatures. [1] [2]
  • Refactored the conditional logic in handle to use instanceof checks for ApplicationCommand and ApplicationCommandAutocomplete, ensuring the correct handling and execution path for each interaction type.

Code clarity and consistency:

  • Replaced isset() checks with direct property checks for member, user, and entitlements on the interaction object to fix a bug where these checks would always return false due to magic method getters being used. [1] [2]
  • Added missing imports for ApplicationCommand, ApplicationCommandAutocomplete, and ApplicationCommandData to support new type hints and improve code clarity.

`isset($interaction->attributes['member'])` would have worked as expected because it checks the array directly, but `isset($interaction->member)` does not work the same way, since it relies on a magic method (`__get`) that only gets invoked if the property is accessed, not when `isset()` is used.
This means the function is effectively misimplemented, because `__get` cannot influence `isset()` checks.
@valzargaming valzargaming merged commit b107687 into master Aug 25, 2025
1 of 2 checks passed
@valzargaming valzargaming changed the title Interaction internals Fix broken caching in interactions Aug 25, 2025
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.

1 participant