Rich Component Base Implementation¶
Implementation of component base classes.
To easily integrate with disnake-compass, it is recommended to inherit from any of these base classes. In any case, it is very much recommended to at least use the ComponentMeta metaclass. Without this, a lot of internal functionality will have to be manually re-implemented.
Classes¶
- class disnake_compass.impl.component.base.ComponentMeta(name: str, bases: tuple[type, ...], namespace: dict[str, Any])[source]¶
Bases:
_ProtocolMetaMetaclass for all disnake-compass component types.
It is highly recommended to use this metaclass for any class that should interface with the components api exposed by disnake-compass.
This metaclass handles
attrsclass generation, custom id completion, interfacing with component managers, parser and factory generation, and automatic slotting.
- asyncas_ui_component
- asynccallback
- clsget_factory
- clsget_manager
- asyncmake_custom_id
- clsset_factory
- clsset_manager
- class disnake_compass.impl.component.base.ComponentBase(*args, **kwargs)[source]¶
Bases:
RichComponent,ProtocolOverarching base class for any kind of component.
Methods¶
- await as_ui_component(manager, /)[source]¶
Convert this component into a component that can be sent by disnake.
- Returns:
A component that can be sent by disnake, maintaining the parameters and custom id set on this rich component.
- Return type:
- abstractmethod await callback(inter, /)[source]¶
Run the component callback.
This should be implemented by the user in each concrete component type.
- Parameters:
interaction – The interaction that caused this button to fire.
- classmethod get_factory()[source]¶
Get the factory that built this component instance.
Note
Component base classes can be declared as a subclass of
Protocols, which tells disnake_compass that this component is a ‘template’ and should not be instantiable. In this case, this attribute defaults to aNoopFactory.In case a concrete component subclass is created, a matching
ComponentFactoryis automatically generated instead.
- classmethod get_manager()[source]¶
Get the manager that was responsible for parsing this component instance.
- await make_custom_id(manager, /)[source]¶
Make a custom id from this component given its current state.
The generated custom id will contain the full state of the component, such that it be used to entirely reconstruct the component later.
Because parameter to string conversion supports asynchronous callbacks, this has to be an async function instead of e.g. a property.
Note
As the logic for translating a component to and from a custom id resides inside the component manager, the component must be registered to a manager to use this method.
- Parameters:
manager (
ComponentManager|None) – The manager to use to make a custom id for this component. This is only relevant if you have multiple managers for the same component. Defaults to the root manager.- Returns:
The custom id representing the full state of this component.
- Return type: