Zum Inhalt

Befehle

Die Decorators an Bot und Router erzeugen diese Objekte; Slash-Befehle erklärt sie.

Optionen

bostie.Option dataclass

Option(*, name: str | None = None, description: str | None = None, name_localizations: Mapping[str, str] | None = None, description_localizations: Mapping[str, str] | None = None, autocomplete: AutocompleteCallback | None = None, min: float | None = None, max: float | None = None, min_length: int | None = None, max_length: int | None = None, channel_types: Iterable[ChannelType] | None = None, file_types: Iterable[str] | None = None, choices: Iterable[Choice | ChoiceValue] | None = None, extra: Mapping[str, Any] | None = None)

Option settings, given as Annotated[int, Option(...)] metadata.

Settings here override what the type hint implies.

name class-attribute instance-attribute

name: str | None = None

description class-attribute instance-attribute

description: str | None = None

name_localizations class-attribute instance-attribute

name_localizations: Mapping[str, str] | None = None

description_localizations class-attribute instance-attribute

description_localizations: Mapping[str, str] | None = None

autocomplete class-attribute instance-attribute

autocomplete: AutocompleteCallback | None = None

min class-attribute instance-attribute

min: float | None = None

max class-attribute instance-attribute

max: float | None = None

min_length class-attribute instance-attribute

min_length: int | None = None

max_length class-attribute instance-attribute

max_length: int | None = None

channel_types class-attribute instance-attribute

channel_types: Iterable[ChannelType] | None = None

file_types class-attribute instance-attribute

file_types: Iterable[str] | None = None

choices class-attribute instance-attribute

choices: Iterable[Choice | ChoiceValue] | None = None

extra class-attribute instance-attribute

extra: Mapping[str, Any] | None = None

bostie.Choice dataclass

Choice(name: str, value: ChoiceValue, *, name_localizations: Mapping[str, str] | None = None)

A choice offered by an option or returned by an autocomplete function.

name instance-attribute

name: str

value instance-attribute

value: ChoiceValue

name_localizations class-attribute instance-attribute

name_localizations: Mapping[str, str] | None = field(default=None, kw_only=True)

bostie.Convert dataclass

Convert(function: Callable[[Any, Any], Any])

Annotated[T, Convert(f)]: f(ctx, value) turns the value into a T.

f may be async, and the option's type comes from its value's type hint.

function instance-attribute

function: Callable[[Any, Any], Any]

bostie.commands.Range

Range[int, 1, 10]: an int, float or str option with inclusive bounds.

Befehle

bostie.commands.Command

Command(callback: CommandCallback, *, router: Router, parent: Group | None = None, settings: Mapping[str, Any])

Bases: _Node

A slash command or subcommand built from an async function.

callback instance-attribute

callback = callback

router instance-attribute

router = router

ephemeral property

ephemeral: bool

Whether answers are ephemeral by default, as set here or on a router.

auto_defer property

auto_defer: float | None

Seconds before an unanswered use is deferred, as set here or above it.

type instance-attribute

type = type

name instance-attribute

name = name

name_localizations instance-attribute

name_localizations = dict(settings['name_localizations'] or {})

guilds instance-attribute

guilds = tuple(settings.get('guilds', ()))

extra instance-attribute

extra = dict(settings['extra'] or {})

description instance-attribute

description = description

description_localizations instance-attribute

description_localizations = dict(settings['description_localizations'] or {})

parent instance-attribute

parent = parent

qualified_name property

qualified_name: str

The full name as typed after the slash, such as "role color set".

on_error

on_error(handler: H) -> H
on_error(exception_type: type[E]) -> Callable[[ErrorHook[E]], ErrorHook[E]]
on_error(first: type[A], second: type[B]) -> Callable[[ErrorHook[A | B]], ErrorHook[A | B]]
on_error(*exception_types: type[BaseException]) -> Callable[[ErrorHook[Any]], ErrorHook[Any]]
on_error(*targets: Any) -> Any

Register async def hook(ctx, error) for the errors of what this covers.

Use @x.on_error for every Exception, or name the exception types.

bostie.commands.Group

Group(name: str, description: str, *, router: Router, parent: Group | None = None, settings: Mapping[str, Any])

Bases: _Node

A slash command made of subcommands, or a subcommand group inside one.

commands instance-attribute

commands: dict[str, Command | Group] = {}

router instance-attribute

router = router

ephemeral property

ephemeral: bool

Whether answers are ephemeral by default, as set here or on a router.

auto_defer property

auto_defer: float | None

Seconds before an unanswered use is deferred, as set here or above it.

type instance-attribute

type = type

name instance-attribute

name = name

name_localizations instance-attribute

name_localizations = dict(settings['name_localizations'] or {})

guilds instance-attribute

guilds = tuple(settings.get('guilds', ()))

extra instance-attribute

extra = dict(settings['extra'] or {})

description instance-attribute

description = description

description_localizations instance-attribute

description_localizations = dict(settings['description_localizations'] or {})

parent instance-attribute

parent = parent

qualified_name property

qualified_name: str

The full name as typed after the slash, such as "role color set".

group

group(name: str, description: str, *, name_localizations: Mapping[str, str] | None = None, description_localizations: Mapping[str, str] | None = None, checks: Iterable[Check] = (), extra: Mapping[str, Any] | None = None) -> Group

Add a subcommand group; groups nest one level deep at most.

command

command(callback: CommandCallback) -> Command
command(callback: None = None, /, *, name: str | None = None, description: str | None = None, name_localizations: Mapping[str, str] | None = None, description_localizations: Mapping[str, str] | None = None, ephemeral: bool | None = None, auto_defer: float | Unset | None = UNSET, checks: Iterable[Check] = (), extra: Mapping[str, Any] | None = None) -> Callable[[CommandCallback], Command]
command(callback: CommandCallback | None = None, /, *, name: str | None = None, description: str | None = None, name_localizations: Mapping[str, str] | None = None, description_localizations: Mapping[str, str] | None = None, ephemeral: bool | None = None, auto_defer: float | Unset | None = UNSET, checks: Iterable[Check] = (), extra: Mapping[str, Any] | None = None) -> Command | Callable[[CommandCallback], Command]

Add a subcommand, as @group.command or @group.command(name=...).

on_error

on_error(handler: H) -> H
on_error(exception_type: type[E]) -> Callable[[ErrorHook[E]], ErrorHook[E]]
on_error(first: type[A], second: type[B]) -> Callable[[ErrorHook[A | B]], ErrorHook[A | B]]
on_error(*exception_types: type[BaseException]) -> Callable[[ErrorHook[Any]], ErrorHook[Any]]
on_error(*targets: Any) -> Any

Register async def hook(ctx, error) for the errors of what this covers.

Use @x.on_error for every Exception, or name the exception types.

bostie.commands.ContextMenuCommand

ContextMenuCommand(type: _TargetType, name: str, callback: CommandCallback, *, router: Router, settings: Mapping[str, Any])

Bases: _Registered

A user or message command, run from the context menu of its target.

callback instance-attribute

callback = callback

router instance-attribute

router = router

ephemeral property

ephemeral: bool

Whether answers are ephemeral by default, as set here or on a router.

auto_defer property

auto_defer: float | None

Seconds before an unanswered use is deferred, as set here or above it.

type instance-attribute

type = type

name instance-attribute

name = name

name_localizations instance-attribute

name_localizations = dict(settings['name_localizations'] or {})

guilds instance-attribute

guilds = tuple(settings.get('guilds', ()))

extra instance-attribute

extra = dict(settings['extra'] or {})

on_error

on_error(handler: H) -> H
on_error(exception_type: type[E]) -> Callable[[ErrorHook[E]], ErrorHook[E]]
on_error(first: type[A], second: type[B]) -> Callable[[ErrorHook[A | B]], ErrorHook[A | B]]
on_error(*exception_types: type[BaseException]) -> Callable[[ErrorHook[Any]], ErrorHook[Any]]
on_error(*targets: Any) -> Any

Register async def hook(ctx, error) for the errors of what this covers.

Use @x.on_error for every Exception, or name the exception types.

bostie.commands.EntryPointCommand

EntryPointCommand(name: str, callback: CommandCallback, *, router: Router, settings: Mapping[str, Any])

Bases: _Registered

The app's entry point command, which opens its Activity from the App Launcher.

description instance-attribute

description = description

description_localizations instance-attribute

description_localizations = dict(settings['description_localizations'] or {})

callback instance-attribute

callback = callback

router instance-attribute

router = router

ephemeral property

ephemeral: bool

Whether answers are ephemeral by default, as set here or on a router.

auto_defer property

auto_defer: float | None

Seconds before an unanswered use is deferred, as set here or above it.

type instance-attribute

type = type

name instance-attribute

name = name

name_localizations instance-attribute

name_localizations = dict(settings['name_localizations'] or {})

guilds instance-attribute

guilds = tuple(settings.get('guilds', ()))

extra instance-attribute

extra = dict(settings['extra'] or {})

on_error

on_error(handler: H) -> H
on_error(exception_type: type[E]) -> Callable[[ErrorHook[E]], ErrorHook[E]]
on_error(first: type[A], second: type[B]) -> Callable[[ErrorHook[A | B]], ErrorHook[A | B]]
on_error(*exception_types: type[BaseException]) -> Callable[[ErrorHook[Any]], ErrorHook[Any]]
on_error(*targets: Any) -> Any

Register async def hook(ctx, error) for the errors of what this covers.

Use @x.on_error for every Exception, or name the exception types.

Routen

bostie.custom_id.ComponentRoute

ComponentRoute(template: str, handler: Callable[P, Coroutine[Any, Any, None]], *, router: Router, settings: Mapping[str, Any])

Bases: Answering

A component or modal handler for a custom_id template like "vote:{up:int}".

template instance-attribute

template = template

handler instance-attribute

handler = handler

names instance-attribute

names = names

router instance-attribute

router = router

ephemeral property

ephemeral: bool

Whether answers are ephemeral by default, as set here or on a router.

auto_defer property

auto_defer: float | None

Seconds before an unanswered use is deferred, as set here or above it.

id

id(**params: str | int) -> str

Build a custom_id that fits in 100 characters and parses back to params.

match

match(custom_id: str) -> dict[str, str | int] | None

The placeholder values in custom_id, or None if it does not fit.

on_error

on_error(handler: H) -> H
on_error(exception_type: type[E]) -> Callable[[ErrorHook[E]], ErrorHook[E]]
on_error(first: type[A], second: type[B]) -> Callable[[ErrorHook[A | B]], ErrorHook[A | B]]
on_error(*exception_types: type[BaseException]) -> Callable[[ErrorHook[Any]], ErrorHook[Any]]
on_error(*targets: Any) -> Any

Register async def hook(ctx, error) for the errors of what this covers.

Use @x.on_error for every Exception, or name the exception types.

Synchronisierung

bostie.SyncResult dataclass

SyncResult(guild_id: int | None, added: tuple[str, ...], removed: tuple[str, ...], changed: tuple[str, ...], ids: Mapping[str, int] = dict[str, int]())

Commands that differed in one scope; guild_id is None for global.

ids holds the id Discord gave each slash command of the scope, by name.

guild_id instance-attribute

guild_id: int | None

added instance-attribute

added: tuple[str, ...]

removed instance-attribute

removed: tuple[str, ...]

changed instance-attribute

changed: tuple[str, ...]

ids class-attribute instance-attribute

ids: Mapping[str, int] = field(default_factory=dict[str, int], compare=False)