Skip to content

Option

Option #

Represents the command option.

channel_types class-attribute instance-attribute #

channel_types: Sequence[ChannelType] = attrs.field(factory=tuple, repr=False, eq=False)

An optional channel types are available for selection.

Note

Available only for the channel option type.

choices class-attribute instance-attribute #

choices: Sequence[Choice] = attrs.field(factory=tuple, repr=False, eq=False)

A list of choices to the option.

description class-attribute instance-attribute #

description: LocalizedOr[str] = attrs.field(default='No description', repr=False, eq=False)

The description of the option.

display_name class-attribute instance-attribute #

display_name: LocalizedOr[str] | None = attrs.field(default=None, repr=False, eq=False)

Display name of option.

Can be localized.

is_required class-attribute instance-attribute #

is_required: bool = attrs.field(default=True, repr=False, eq=False)

An optional flag is the option is required.

Default: True

max_length class-attribute instance-attribute #

max_length: int | None = attrs.field(default=None, repr=False, eq=False)

An optional maximum length of the option value.

Note

Available only for the string option type.

max_value class-attribute instance-attribute #

max_value: int | None = attrs.field(default=None, repr=False, eq=False)

An optional maximum value of the option value.

Note

Available only for the integer/float option type.

min_length class-attribute instance-attribute #

min_length: int | None = attrs.field(default=None, repr=False, eq=False)

An optional minimum length of the option value.

Note

Available only for the string option type.

min_value class-attribute instance-attribute #

min_value: int | None = attrs.field(default=None, repr=False, eq=False)

An optional minimum value of the option value.

Note

Available only for the integer/float option type.

name instance-attribute #

name: str

The unique name of the option.

type instance-attribute #

type: OptionType

The option type.

Example#

class UserCommand(SlashCommand):
    def __init__(self) -> None:
        super().__init__(name="user")

    @sub_command(
        name="info",
        description="Get information about user",
        options=[
            Option(
                type=OptionType.USER,
                name="user",
                description="About who you want to know (or put an ID)",
                is_required=False,
            )
        ],
    )
    async def user_info(
        self, context: InteractionContext, user: InteractionMember | User | None = None
    ) -> None:
        if not user:
            user = context.interaction.user
        return await context.create_response(
            content=f"User **\@{user.username}**\ncreated at: <t:{round(user.created_at.timestamp())}:R>\nID: {user.id}"
        )