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

[BUG] Error starting when using scope param in command decorator #1214

Closed
1 task done
H3rmt opened this issue Jan 1, 2023 · 1 comment · Fixed by #1217
Closed
1 task done

[BUG] Error starting when using scope param in command decorator #1214

H3rmt opened this issue Jan 1, 2023 · 1 comment · Fixed by #1217
Assignees
Labels
bug Something isn't working

Comments

@H3rmt
Copy link
Contributor

H3rmt commented Jan 1, 2023

Describe the bug.

When starting the bot with a command that has a scope as a param specified it results in a KeyError:

Could not prepare the client:
Traceback (most recent call last):
  File "----/venv/lib/python3.10/site-packages/interactions/client/bot.py", line 404, in _ready
    await self.__sync()
  File "----/venv/lib/python3.10/site-packages/interactions/client/bot.py", line 621, in __sync
    if _guild_command["name"] not in __check_guild_commands[_guild_id]:
KeyError: None

List the steps.

  1. Create a bot:
ids = 8210301307------
bot = interactions.Client(token="", default_scope=ids)
  1. Create a command with a scope param:
@bot.command(
    name="test",
    description="test",
    scope=ids
)
async def _test(ctx):
    await ctx.send("test")
  1. run the bot
  2. see Traceback

What you expected.

The command should be correctly registered for the guilds provided in the default_scope and command scope

File client/bot.py, line 517, in __resolve_commands:

if cmd.default_scope and self._default_scope:
    cmd.scope = (
        cmd.scope.extend(self._default_scope)
        if isinstance(cmd.scope, list)
        else self._default_scope
    )

cmd.scope.extend(self._default_scope)
extends the cmd.scope, but then sets cmd.scope to its return value, which is None.
This overrides the scope, resulting in None being passed as the scope to command in full_data.
This passes None as the guild_id to the ApplicationCommand, which is used in when getting a guild_commands _guild_id
=> KeyError here if _guild_command["name"] not in __check_guild_commands[_guild_id]:

replace

if cmd.default_scope and self._default_scope:
  cmd.scope = (
      cmd.scope.extend(self._default_scope)
      if isinstance(cmd.scope, list)
      else self._default_scope
  )

with

if cmd.default_scope and self._default_scope:
  if isinstance(cmd.scope, list):
    cmd.scope.extend(self._default_scope)
  else:
    cmd.scope = self._default_scope

What you saw.

Instead, I received this traceback error given from my Python terminal:

Could not prepare the client:
Traceback (most recent call last):
  File "----/venv/lib/python3.10/site-packages/interactions/client/bot.py", line 404, in _ready
    await self.__sync()
  File "----/venv/lib/python3.10/site-packages/interactions/client/bot.py", line 621, in __sync
    if _guild_command["name"] not in __check_guild_commands[_guild_id]:
KeyError: None

What version of the library did you use?

stable

Version specification

4.3.4

Code of Conduct

  • I agree to follow the contribution requirements.
@H3rmt H3rmt added the bug Something isn't working label Jan 1, 2023
@Damego
Copy link
Member

Damego commented Jan 2, 2023

Does your solution works? If yes would you like to make a pull request then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants