risa.ui.build¶
Building a view's layout into the components of a message.
BuildContext
¶
BuildContext(
cookie: str,
tokens: Set[str],
cls: type[View],
wire_codec: Codec,
*,
slots: Sequence[Slot] | None = None,
reserve: int = 0,
)
What a component gets while a view is built: the view's routing identity and codec.
risa makes one for each pass over a layout: one to measure it and one for each time it
emits, so a component's build runs at least twice per client.build.
Attributes:
-
cookie(str) –The cookie the view routes under.
-
tokens(Set[str]) –The routing tokens of the view's handlers.
-
cls(type[View]) –The view class being built.
-
codec(Codec) –The codec the view's state is written in.
capacities
property
¶
The spare characters of each interactive component built so far.
routing_id
¶
Return the custom_id for an interactive component bound to binding.
Parameters:
-
binding(Binding) –The handler the component routes to, with its wire arguments.
-
path(str) –Where the component stands in the tree, for error messages.
Returns:
-
str–The
custom_id, carrying the route, the wire arguments and the component's share of the state.
Raises:
-
LayoutError–If the handler belongs to another view.
-
ArgBindError–If a wire argument is too long to carry.
-
CustomIdOverflowError–If the
custom_idwould exceed Discord's limit.
Rendered
¶
Rendered(components: Sequence[ComponentBuilder])
A built view: the components of a message, ready to send.
It is a mapping, so it spreads into any call that takes components=:
await ctx.respond(**rendered). A Components V2 message carries nothing but its
components, so there is nothing else to spread. Client.build returns one.
respond_to
async
¶
respond_to(
rest: RESTClient,
interaction: ComponentInteraction | ModalInteraction | CommandInteraction,
*,
ephemeral: bool = False,
**forbidden: Never,
) -> None
Answer interaction with the view, as its initial response.
For interactions risa does not dispatch, such as slash commands. In a risa handler,
answer with ctx.respond(**rendered) instead, which knows whether the interaction
has been answered already.
Parameters:
-
rest(RESTClient) –The REST client to answer through.
-
interaction(ComponentInteraction | ModalInteraction | CommandInteraction) –The interaction to answer, which must not have an initial response yet.
-
ephemeral(bool, default:False) –Show the message only to the user who used the command.
-
**forbidden(Never, default:{}) –Nothing: a V2 view renders the whole message, so any keyword raises
TypeError.
send_to
async
¶
send_to(
rest: RESTClient,
channel: SnowflakeishOr[TextableChannel],
**forbidden: Never,
) -> Message
Send the view as a new message in channel.
Parameters:
-
rest(RESTClient) –The REST client to send through.
-
channel(SnowflakeishOr[TextableChannel]) –The channel, or its id, to send to.
-
**forbidden(Never, default:{}) –Nothing: a V2 view renders the whole message, so any keyword raises
TypeError.
Returns:
-
Message–The message sent.