Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly fix component/modal callback #1523

Merged

Conversation

AstreaTSS
Copy link
Member

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

component_callback and modal_callback was always using the function name after the last patch due to some weirdness. This PR fixes that by simplifying the patch and... fixing parts of the patch itself, funny enough.

Frankly, I'm disappointed in myself how easy this fix was 😅.

Changes

  • Pass in custom_id to the unpack helper/validator, not the empty resolved_custom_id.
  • Removed the unused (other than for the mistake above) resolved_custom_id initial declaration - I think we all forgot that resolved_custom_id does not get passed into there without a nonlocal. No idea how custom_id does in this specific case, but it does.
    • Yes, this patch makes the code very similar to the code before the first patch. However, since the variable name inside the wrapper function is different from just custom_id, everything works now (for some reason).

Related Issues

Test Scenarios

@interactions.slash_command(name="test", description="My command")
async def test(ctx: interactions.SlashContext):
    await ctx.send(
        components=interactions.Button(
            style=interactions.ButtonStyle.PRIMARY, label="Test", custom_id="test"
        )
    )


@interactions.component_callback("test")
async def test_callback(ctx: interactions.ComponentContext):
    await ctx.edit_origin(content="Test")

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

Copy link
Member

@silasary silasary left a comment

Choose a reason for hiding this comment

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

nonlocal was only needed because we were redefining a name used in a higher scope.

This is much nicer

@silasary silasary merged commit b1f780b into interactions-py:unstable Aug 8, 2023
1 check passed
@silasary silasary mentioned this pull request Aug 8, 2023
@AstreaTSS AstreaTSS deleted the component-callback-proper-fix branch August 16, 2023 19:44
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.

2 participants