Skip to content

fix: correctly serialize slash cmd with same names from different scope #1733

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

Merged
merged 1 commit into from
Aug 24, 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

Trying to make two non-sub slash commands with the same name but a different scopes results in an error message when trying to sync these slash commands.

This is because our application_commands_to_dict, if multiple slash commands under the same name were found, only used the scope of the first command in the list for serialization purposes.

This later causes issues between the dict generated by this command and bot.interactions_by_scope since interactions_by_scope now has a command in a scope that application_commands_to_dict did not account for, causing an error when syncing.

This PR fixes all of that by making sure all slash commands with the same name are properly serialized. Because I was there already, this PR also refactors application_commands_to_dict a tiny bit to be nicer.

Changes

  • Include all commands in cmd_list (a list representing slash commands with the same name) in the final, serialized result instead of only taking the scope of the first command and ignoring other commands.
  • Did a little refactoring to application_commands_to_dict since I was here anyways.

Related Issues

N/A

Test Scenarios

import interactions as ipy

bot = ipy.Client(sync_interactions=True, delete_unused_application_cmds=True, ...)

@ipy.slash_command(name="test", scopes=[GUILD_1])
async def test(ctx: ipy.SlashContext):
    await ctx.send("Hello, world!")

@ipy.slash_command(name="test", scopes=[GUILD_2])
async def test2(ctx: ipy.SlashContext):
    await ctx.send("Hello, world!")

bot.start()

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
Copy link
Member Author

Subcommands do not have this fix. Frankly, I'm unsure how this would even be fixed with them, and it might be impossible without some major refactorings, so it has been left as is.

Copy link

@syntaxsdev syntaxsdev left a comment

Choose a reason for hiding this comment

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

thanks for this fix, I've tested this for this behavior in my environment and it performs as intended.

@syntaxsdev
Copy link

bump, need approval :)

@silasary silasary merged commit d5dfe8e into interactions-py:unstable Aug 24, 2024
2 checks passed
@AstreaTSS AstreaTSS deleted the multi-scope-name-fix branch January 3, 2025 02:25
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.

3 participants