Skip to content

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

@H3rmt

Description

@H3rmt

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.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions