Skip to content

[BUG] slash_user_option (and probably others) fail to register if name is not explicitly provided #1554

Closed
@Wizzerinus

Description

@Wizzerinus

Library Version

5.10.0

Describe the Bug

slash_user_command's docstring says:

    """
    Annotates an argument as a user type slash command option.

    Args:
        description: The description of your option
        required: Is this option required?
        autocomplete: Use autocomplete for this option
        name: The name of the option. Defaults to the name of the argument

    """

Defaults to the name of the argument

However using an argument like:

    async def my_command(
        self, ctx: SlashContext, user: slash_user_option("Some user", required=True)
    ):

Results in a gateway error and the command not being registered:

bot.internal: INFO     Overwriting 0 with 1 application commands
bot.internal: ERROR    PUT::https://discord.com/api/v10/applications/BOT_ID/commands: 400
bot.internal: ERROR    Error in command `do_something`: options->None->name APPLICATION_COMMAND_INVALID_NAME: Command name is invalid

This also happens outside of extensions (see minimal reproducible code). Not sure if this is a code bug or a documentation bug, but feels like a code bug.

Steps to Reproduce

See minimal reproducible code

Expected Results

A slash command do_something is created with a single argument named user

Minimal Reproducible Code

import logging

from interactions import Client, Intents, Permissions, SlashContext, slash_command, slash_user_option

logger = logging.getLogger("bot.internal")
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter("%(name)-12s: %(levelname)-8s %(message)s")
console.setFormatter(formatter)
global_logger = logging.getLogger("bot")
global_logger.setLevel(logging.INFO)
global_logger.addHandler(console)

bot = Client(intents=Intents.DEFAULT, logger=logger)


@slash_command(
    description="Do something.",
    default_member_permissions=Permissions.ADMINISTRATOR
)
async def do_something(
    ctx: SlashContext, user: slash_user_option("The user to do something with.", required=True)
):  # note there's no name="user" provided!
    await ctx.respond(f"Hello {user.mention}!")

bot.start("token")

Traceback

No unless gateway error counts with logging enabled
Gateway error

bot.internal: INFO     Overwriting 0 with 1 application commands
bot.internal: ERROR    PUT::https://discord.com/api/v10/applications/BOT_ID/commands: 400
bot.internal: ERROR    Error in command `do_something`: options->None->name APPLICATION_COMMAND_INVALID_NAME: Command name is invalid

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.
  • I have attempted to debug this myself, and I believe this issue is with the library

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions