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: hook onto add_command to propagate errors correctly #1678

Merged
merged 2 commits into from
May 6, 2024

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

Errors generated when adding prefixed and hybrid commands were not being propagated as they should, as due to being a separated extension, they would error out like a listener instead of like add_command. This caused some fun situations, like the one noted in #1668.

This PR fixes that by adding a way of adding "hooks" onto add_command directly, and then making prefixed and hybrid commands use that hook for its register command logic.

Changes

  • Add Client._add_command_hook, which is a list of functions to run during add_command.
  • Make prefixed commands and hybrid commands use the hook.
    • This required modifying the register command logic a bit to make the function not async. This would be technically breaking for hybrid commands due to me not using an underscore, so the old function was kept as a wrapper for the new one.

Related Issues

Test Scenarios

@hybrid_slash_command()
@slash_option(
    "test", "The test option", OptionType.STRING, required=True, autocomplete=True
)
async def test(ctx: HybridContext, test: str):
    await ctx.send(f"Test: {test}")
@prefixed_command()
async def test(ctx: PrefixedContext):
    await ctx.send("Hello!")

@prefixed_command(name="test")
async def test2(ctx: PrefixedContext):
    await ctx.send("Hello!")

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

@AstreaTSS AstreaTSS changed the base branch from stable to unstable May 6, 2024 04:49
@silasary silasary enabled auto-merge (squash) May 6, 2024 05:06
@silasary silasary merged commit a8f6fcf into interactions-py:unstable May 6, 2024
4 checks passed
@AstreaTSS AstreaTSS deleted the add-command-hook branch May 6, 2024 05:19
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