Skip to content

Options

The Option class provides type-safe decorators for registering command options. Each static method corresponds to a Discord option type and ensures type correctness at the Python level.

Using options

Options are registered using Option static methods as decorators on command callbacks:

from fastapi_interactions.commands import CommandRouter, Option

@router.command(name="greet", description="Greet someone")
@Option.string(name="name", description="Who to greet", required=True)
async def greet(ctx, name: str):
    return f"Hello, {name}!"

The parameter name in your function must match the option name. The framework automatically binds option values to function parameters.

Available options

String options

@Option.string(name="text", description="Some text", required=True)

Accepts any text input. Default option type if no specific type is needed.

Integer options

@Option.integer(name="count", description="A number", required=True)

Accepts whole numbers only. Discord enforces integer validation client-side.

Number options

@Option.number(name="price", description="A decimal", required=True)

Accepts decimal numbers (floats). Use for prices, ratings, percentages, or any fractional value.

Boolean options

@Option.boolean(name="enabled", description="Toggle this", required=True)

Presents a true/false toggle to the user.

User options

@Option.user(name="target", description="Pick a user", required=True)

Discord's user picker. The parameter receives a snowflake ID (string) of the selected user.

Channel options

@Option.channel(name="target", description="Pick a channel", required=True)

Discord's channel picker. The parameter receives a snowflake ID (string) of the selected channel.

Role options

@Option.role(name="role", description="Pick a role", required=True)

Discord's role picker. The parameter receives a snowflake ID (string) of the selected role.

Mentionable options

@Option.mentionable(name="target", description="User or role", required=True)

Combines user and role pickers. The parameter receives a snowflake ID (string) that can be either a user or role.

Reference

fastapi_interactions.commands.Option

Source code in fastapi_interactions/commands.py
class Option:
    @staticmethod
    def __create_operation_decorator(name: str, description: str, option_type: OptionType, required: bool = True):
        def decorator(func):
            meta = getattr(
                func, '_command_meta', CommandMeta(name='', description='', type=1)
            )

            meta.options.insert(
                0,
                CommandOption(
                    name=name,
                    description=description,
                    type=option_type,
                    required=required
                )
            )
            func._command_meta = meta
            return func
        return decorator

    @staticmethod
    def string(name: str, description: str, required: bool = True):
        """Register a string option on a command.

        Decorates a command callback to add a string option parameter. The option name
        must match a parameter name in the callback for automatic value binding.

        Args:
            name: The option name. Must match a callback parameter name.
            description: Human-readable description shown to Discord users.
            required: Whether the option is required. Defaults to True.

        Returns:
            A decorator that attaches the option metadata to the function.

        Example:
        ```python
        @router.command(name="echo", description="Echo text")
        @Option.string(name="text", description="Text to echo", required=True)
        async def echo(ctx, text: str):
            return text
        ```
        """
        return Option.__create_operation_decorator(
            name=name,
            description=description,
            option_type=OptionType.STRING,
            required=required
        )

    @staticmethod
    def integer(name: str, description: str, required: bool = True):
        """Register an integer option on a command.

        Decorates a command callback to add an integer option parameter. The option name
        must match a parameter name in the callback for automatic value binding.

        Args:
            name: The option name. Must match a callback parameter name.
            description: Human-readable description shown to Discord users.
            required: Whether the option is required. Defaults to True.

        Returns:
            A decorator that attaches the option metadata to the function.

        Example:
        ```python
        @router.command(name="echo", description="Echo integer")
        @Option.integer(name="number", description="Integer to echo", required=True)
        async def echo(ctx, number: int):
            return int
        ```
        """
        return Option.__create_operation_decorator(
            name=name,
            description=description,
            option_type=OptionType.INTEGER,
            required=required
        )

    @staticmethod
    def user(name: str, description: str, required: bool = True):
        """Register a user option on a command.

        Decorates a command callback to add a user option parameter. The option name
        must match a parameter name in the callback for automatic value binding.

        Args:
            name: The option name. Must match a callback parameter name.
            description: Human-readable description shown to Discord users.
            required: Whether the option is required. Defaults to True.

        Returns:
            A decorator that attaches the option metadata to the function.

        Example:
        ```python
        @router.command(name="kick", description="Kick a user")
        @Option.user(name="user", description="Target user to kick", required=True)
        async def kick(ctx, user: Snowflake):
            ...
            return 'User kicked'
        ```
        """
        return Option.__create_operation_decorator(
            name=name,
            description=description,
            option_type=OptionType.USER,
            required=required
        )

    @staticmethod
    def channel(name: str, description: str, required: bool = True):
        """Register a channel option on a command.

        Decorates a command callback to add a channel option parameter. The option name
        must match a parameter name in the callback for automatic value binding.

        Args:
            name: The option name. Must match a callback parameter name.
            description: Human-readable description shown to Discord users.
            required: Whether the option is required. Defaults to True.

        Returns:
            A decorator that attaches the option metadata to the function.

        Example:
        ```python
        @router.command(name="purge", description="Purge a channel")
        @Option.user(name="channel", description="Target channel to purge", required=True)
        async def purge(ctx, channel: Snowflake):
            ...
            return 'Channel purged'
        ```
        """
        return Option.__create_operation_decorator(
            name=name,
            description=description,
            option_type=OptionType.CHANNEL,
            required=required
        )

    @staticmethod
    def role(name: str, description: str, required: bool = True):
        """Register a role option on a command.

        Decorates a command callback to add a channel option parameter. The option name
        must match a parameter name in the callback for automatic value binding.

        Args:
            name: The option name. Must match a callback parameter name.
            description: Human-readable description shown to Discord users.
            required: Whether the option is required. Defaults to True.

        Returns:
            A decorator that attaches the option metadata to the function.

        Example:
        ```python
        @router.command(name="rmrole", description="Delete a role")
        @Option.role(name="role", description="role to delete", required=True)
        async def purge(ctx, role: Snowflake):
            ...
            return 'Role purged'
        ```
        """
        return Option.__create_operation_decorator(
            name=name,
            description=description,
            option_type=OptionType.ROLE,
            required=required
        )

    @staticmethod
    def mentionable(name: str, description: str, required: bool = True):
        """Register a mentionable option on a command.

        Decorates a command callback to add a channel option parameter. The option name
        must match a parameter name in the callback for automatic value binding.

        Args:
            name: The option name. Must match a callback parameter name.
            description: Human-readable description shown to Discord users.
            required: Whether the option is required. Defaults to True.

        Returns:
            A decorator that attaches the option metadata to the function.

        Example:
        ```python
        @router.command(name="warn", description="Warn a user or role")
        @Option.mentionable(name="target", description="User or role to warn", required=True)
        async def warn(ctx, target: Snowflake):
            return f"⚠️ Warning issued to <@&{target}>"
        ```
        """
        return Option.__create_operation_decorator(
            name=name,
            description=description,
            option_type=OptionType.MENTIONABLE,
            required=required
        )

    @staticmethod
    def boolean(name: str, description: str, required: bool = True):
        """Register a boolean option on a command.

        Decorates a command callback to add a boolean option parameter. The option name
        must match a parameter name in the callback for automatic value binding.

        Args:
            name: The option name. Must match a callback parameter name.
            description: Human-readable description shown to Discord users.
            required: Whether the option is required. Defaults to True.

        Returns:
            A decorator that attaches the option metadata to the function.

        Example:
        ```python
        @router.command(name="ban", description="Ban a user")
        @Option.user(name="target", description="User to ban", required=True)
        @Option.boolean(name="soft", description="Is this a softban", required=True)
        async def warn(ctx, target: Snowflake, soft: bool):
            if soft:
                ...
            else:
                ...
            return 'Command executed'
        ```
        """
        return Option.__create_operation_decorator(
            name=name,
            description=description,
            option_type=OptionType.BOOLEAN,
            required=required
        )

    @staticmethod
    def number(name: str, description: str, required: bool = True):
        """Register a number option on a command.

        Decorates a command callback to add a number option parameter. The option name
        must match a parameter name in the callback for automatic value binding.
        This is a float in python.

        Args:
            name: The option name. Must match a callback parameter name.
            description: Human-readable description shown to Discord users.
            required: Whether the option is required. Defaults to True.

        Returns:
            A decorator that attaches the option metadata to the function.

        Example:
        ```python
        @router.command(name="rate", description="Rate something")
        @Option.number(name="score", description="Rating from 0 to 10", required=True)
        async def rate(ctx, score: float):
            return f"Rating: {score}/10 ⭐"
        ```
        """
        return Option.__create_operation_decorator(
            name=name,
            description=description,
            option_type=OptionType.NUMBER,
            required=required
        )

boolean staticmethod

boolean(name: str, description: str, required: bool = True)

Register a boolean option on a command.

Decorates a command callback to add a boolean option parameter. The option name must match a parameter name in the callback for automatic value binding.

Parameters:

Name Type Description Default
name str

The option name. Must match a callback parameter name.

required
description str

Human-readable description shown to Discord users.

required
required bool

Whether the option is required. Defaults to True.

True

Returns:

Type Description

A decorator that attaches the option metadata to the function.

Example:

@router.command(name="ban", description="Ban a user")
@Option.user(name="target", description="User to ban", required=True)
@Option.boolean(name="soft", description="Is this a softban", required=True)
async def warn(ctx, target: Snowflake, soft: bool):
    if soft:
        ...
    else:
        ...
    return 'Command executed'

Source code in fastapi_interactions/commands.py
@staticmethod
def boolean(name: str, description: str, required: bool = True):
    """Register a boolean option on a command.

    Decorates a command callback to add a boolean option parameter. The option name
    must match a parameter name in the callback for automatic value binding.

    Args:
        name: The option name. Must match a callback parameter name.
        description: Human-readable description shown to Discord users.
        required: Whether the option is required. Defaults to True.

    Returns:
        A decorator that attaches the option metadata to the function.

    Example:
    ```python
    @router.command(name="ban", description="Ban a user")
    @Option.user(name="target", description="User to ban", required=True)
    @Option.boolean(name="soft", description="Is this a softban", required=True)
    async def warn(ctx, target: Snowflake, soft: bool):
        if soft:
            ...
        else:
            ...
        return 'Command executed'
    ```
    """
    return Option.__create_operation_decorator(
        name=name,
        description=description,
        option_type=OptionType.BOOLEAN,
        required=required
    )

channel staticmethod

channel(name: str, description: str, required: bool = True)

Register a channel option on a command.

Decorates a command callback to add a channel option parameter. The option name must match a parameter name in the callback for automatic value binding.

Parameters:

Name Type Description Default
name str

The option name. Must match a callback parameter name.

required
description str

Human-readable description shown to Discord users.

required
required bool

Whether the option is required. Defaults to True.

True

Returns:

Type Description

A decorator that attaches the option metadata to the function.

Example:

@router.command(name="purge", description="Purge a channel")
@Option.user(name="channel", description="Target channel to purge", required=True)
async def purge(ctx, channel: Snowflake):
    ...
    return 'Channel purged'

Source code in fastapi_interactions/commands.py
@staticmethod
def channel(name: str, description: str, required: bool = True):
    """Register a channel option on a command.

    Decorates a command callback to add a channel option parameter. The option name
    must match a parameter name in the callback for automatic value binding.

    Args:
        name: The option name. Must match a callback parameter name.
        description: Human-readable description shown to Discord users.
        required: Whether the option is required. Defaults to True.

    Returns:
        A decorator that attaches the option metadata to the function.

    Example:
    ```python
    @router.command(name="purge", description="Purge a channel")
    @Option.user(name="channel", description="Target channel to purge", required=True)
    async def purge(ctx, channel: Snowflake):
        ...
        return 'Channel purged'
    ```
    """
    return Option.__create_operation_decorator(
        name=name,
        description=description,
        option_type=OptionType.CHANNEL,
        required=required
    )

integer staticmethod

integer(name: str, description: str, required: bool = True)

Register an integer option on a command.

Decorates a command callback to add an integer option parameter. The option name must match a parameter name in the callback for automatic value binding.

Parameters:

Name Type Description Default
name str

The option name. Must match a callback parameter name.

required
description str

Human-readable description shown to Discord users.

required
required bool

Whether the option is required. Defaults to True.

True

Returns:

Type Description

A decorator that attaches the option metadata to the function.

Example:

@router.command(name="echo", description="Echo integer")
@Option.integer(name="number", description="Integer to echo", required=True)
async def echo(ctx, number: int):
    return int

Source code in fastapi_interactions/commands.py
@staticmethod
def integer(name: str, description: str, required: bool = True):
    """Register an integer option on a command.

    Decorates a command callback to add an integer option parameter. The option name
    must match a parameter name in the callback for automatic value binding.

    Args:
        name: The option name. Must match a callback parameter name.
        description: Human-readable description shown to Discord users.
        required: Whether the option is required. Defaults to True.

    Returns:
        A decorator that attaches the option metadata to the function.

    Example:
    ```python
    @router.command(name="echo", description="Echo integer")
    @Option.integer(name="number", description="Integer to echo", required=True)
    async def echo(ctx, number: int):
        return int
    ```
    """
    return Option.__create_operation_decorator(
        name=name,
        description=description,
        option_type=OptionType.INTEGER,
        required=required
    )

mentionable staticmethod

mentionable(name: str, description: str, required: bool = True)

Register a mentionable option on a command.

Decorates a command callback to add a channel option parameter. The option name must match a parameter name in the callback for automatic value binding.

Parameters:

Name Type Description Default
name str

The option name. Must match a callback parameter name.

required
description str

Human-readable description shown to Discord users.

required
required bool

Whether the option is required. Defaults to True.

True

Returns:

Type Description

A decorator that attaches the option metadata to the function.

Example:

@router.command(name="warn", description="Warn a user or role")
@Option.mentionable(name="target", description="User or role to warn", required=True)
async def warn(ctx, target: Snowflake):
    return f"⚠️ Warning issued to <@&{target}>"

Source code in fastapi_interactions/commands.py
@staticmethod
def mentionable(name: str, description: str, required: bool = True):
    """Register a mentionable option on a command.

    Decorates a command callback to add a channel option parameter. The option name
    must match a parameter name in the callback for automatic value binding.

    Args:
        name: The option name. Must match a callback parameter name.
        description: Human-readable description shown to Discord users.
        required: Whether the option is required. Defaults to True.

    Returns:
        A decorator that attaches the option metadata to the function.

    Example:
    ```python
    @router.command(name="warn", description="Warn a user or role")
    @Option.mentionable(name="target", description="User or role to warn", required=True)
    async def warn(ctx, target: Snowflake):
        return f"⚠️ Warning issued to <@&{target}>"
    ```
    """
    return Option.__create_operation_decorator(
        name=name,
        description=description,
        option_type=OptionType.MENTIONABLE,
        required=required
    )

number staticmethod

number(name: str, description: str, required: bool = True)

Register a number option on a command.

Decorates a command callback to add a number option parameter. The option name must match a parameter name in the callback for automatic value binding. This is a float in python.

Parameters:

Name Type Description Default
name str

The option name. Must match a callback parameter name.

required
description str

Human-readable description shown to Discord users.

required
required bool

Whether the option is required. Defaults to True.

True

Returns:

Type Description

A decorator that attaches the option metadata to the function.

Example:

@router.command(name="rate", description="Rate something")
@Option.number(name="score", description="Rating from 0 to 10", required=True)
async def rate(ctx, score: float):
    return f"Rating: {score}/10 ⭐"

Source code in fastapi_interactions/commands.py
@staticmethod
def number(name: str, description: str, required: bool = True):
    """Register a number option on a command.

    Decorates a command callback to add a number option parameter. The option name
    must match a parameter name in the callback for automatic value binding.
    This is a float in python.

    Args:
        name: The option name. Must match a callback parameter name.
        description: Human-readable description shown to Discord users.
        required: Whether the option is required. Defaults to True.

    Returns:
        A decorator that attaches the option metadata to the function.

    Example:
    ```python
    @router.command(name="rate", description="Rate something")
    @Option.number(name="score", description="Rating from 0 to 10", required=True)
    async def rate(ctx, score: float):
        return f"Rating: {score}/10 ⭐"
    ```
    """
    return Option.__create_operation_decorator(
        name=name,
        description=description,
        option_type=OptionType.NUMBER,
        required=required
    )

role staticmethod

role(name: str, description: str, required: bool = True)

Register a role option on a command.

Decorates a command callback to add a channel option parameter. The option name must match a parameter name in the callback for automatic value binding.

Parameters:

Name Type Description Default
name str

The option name. Must match a callback parameter name.

required
description str

Human-readable description shown to Discord users.

required
required bool

Whether the option is required. Defaults to True.

True

Returns:

Type Description

A decorator that attaches the option metadata to the function.

Example:

@router.command(name="rmrole", description="Delete a role")
@Option.role(name="role", description="role to delete", required=True)
async def purge(ctx, role: Snowflake):
    ...
    return 'Role purged'

Source code in fastapi_interactions/commands.py
@staticmethod
def role(name: str, description: str, required: bool = True):
    """Register a role option on a command.

    Decorates a command callback to add a channel option parameter. The option name
    must match a parameter name in the callback for automatic value binding.

    Args:
        name: The option name. Must match a callback parameter name.
        description: Human-readable description shown to Discord users.
        required: Whether the option is required. Defaults to True.

    Returns:
        A decorator that attaches the option metadata to the function.

    Example:
    ```python
    @router.command(name="rmrole", description="Delete a role")
    @Option.role(name="role", description="role to delete", required=True)
    async def purge(ctx, role: Snowflake):
        ...
        return 'Role purged'
    ```
    """
    return Option.__create_operation_decorator(
        name=name,
        description=description,
        option_type=OptionType.ROLE,
        required=required
    )

string staticmethod

string(name: str, description: str, required: bool = True)

Register a string option on a command.

Decorates a command callback to add a string option parameter. The option name must match a parameter name in the callback for automatic value binding.

Parameters:

Name Type Description Default
name str

The option name. Must match a callback parameter name.

required
description str

Human-readable description shown to Discord users.

required
required bool

Whether the option is required. Defaults to True.

True

Returns:

Type Description

A decorator that attaches the option metadata to the function.

Example:

@router.command(name="echo", description="Echo text")
@Option.string(name="text", description="Text to echo", required=True)
async def echo(ctx, text: str):
    return text

Source code in fastapi_interactions/commands.py
@staticmethod
def string(name: str, description: str, required: bool = True):
    """Register a string option on a command.

    Decorates a command callback to add a string option parameter. The option name
    must match a parameter name in the callback for automatic value binding.

    Args:
        name: The option name. Must match a callback parameter name.
        description: Human-readable description shown to Discord users.
        required: Whether the option is required. Defaults to True.

    Returns:
        A decorator that attaches the option metadata to the function.

    Example:
    ```python
    @router.command(name="echo", description="Echo text")
    @Option.string(name="text", description="Text to echo", required=True)
    async def echo(ctx, text: str):
        return text
    ```
    """
    return Option.__create_operation_decorator(
        name=name,
        description=description,
        option_type=OptionType.STRING,
        required=required
    )

user staticmethod

user(name: str, description: str, required: bool = True)

Register a user option on a command.

Decorates a command callback to add a user option parameter. The option name must match a parameter name in the callback for automatic value binding.

Parameters:

Name Type Description Default
name str

The option name. Must match a callback parameter name.

required
description str

Human-readable description shown to Discord users.

required
required bool

Whether the option is required. Defaults to True.

True

Returns:

Type Description

A decorator that attaches the option metadata to the function.

Example:

@router.command(name="kick", description="Kick a user")
@Option.user(name="user", description="Target user to kick", required=True)
async def kick(ctx, user: Snowflake):
    ...
    return 'User kicked'

Source code in fastapi_interactions/commands.py
@staticmethod
def user(name: str, description: str, required: bool = True):
    """Register a user option on a command.

    Decorates a command callback to add a user option parameter. The option name
    must match a parameter name in the callback for automatic value binding.

    Args:
        name: The option name. Must match a callback parameter name.
        description: Human-readable description shown to Discord users.
        required: Whether the option is required. Defaults to True.

    Returns:
        A decorator that attaches the option metadata to the function.

    Example:
    ```python
    @router.command(name="kick", description="Kick a user")
    @Option.user(name="user", description="Target user to kick", required=True)
    async def kick(ctx, user: Snowflake):
        ...
        return 'User kicked'
    ```
    """
    return Option.__create_operation_decorator(
        name=name,
        description=description,
        option_type=OptionType.USER,
        required=required
    )