Base classes#

Components#

Buttons#

class components.api.component.RichButton[source]#

Bases: RichComponent, Protocol

Baseline protocol for Button-like components.

label: str | None#

The label of the component.

Either or both this field or the emoji field must be set.

style: ButtonStyle#

The style of the component.

This dictates how the button is displayed on discord.

emoji: str | PartialEmoji | Emoji | None#

The emoji that is to be displayed on this button.

Either or both this field or the emoji field must be set.

disabled: bool#

Whether or not this button is disabled.

A disabled button is greyed out on discord, and cannot be pressed. Disabled buttons can therefore not cause any interactions, either.

async as_ui_component() Button[None][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:

disnake.ui.WrappedComponent

Select Menus#

class components.api.component.RichComponent[source]#

Bases: Protocol

The baseline protocol for any kind of component.

Any and all components must implement this protocol in order to be properly handled by disnake-ext-components.

classmethod should_invoke_for(_RichComponent__interaction: Interaction) bool[source]#

Determine whether to fire this component’s callback.

This is done by determining whether the passed interaction has a custom id that matches that of this component type.

Parameters:

interaction (disnake.Interaction) – The interaction to check.

Returns:

Whether or not a component of this kind caused the interaction.

Return type:

bool

async classmethod loads(_RichComponent__interaction: Any) typing_extensions.Self[source]#

Load a fully-fledged component from an interaction.

The interaction’s custom id will be used to parse any special parameters.

Parameters:

interaction (disnake.Interaction) – The interaction from which to take the component data.

Returns:

An instance of this class with parameters extracted and parsed from the custom id.

Return type:

ComponentBase

async dumps() str[source]#

Dump an instance of this class into a custom id string.

This ensures all special parameters are stored on the string in such a way that they can be losslessly loaded in the future by means of loads().

Returns:

The parsed custom id.

Return type:

str

async callback(_RichComponent__interaction: Interaction) None[source]#

Run the component callback.

This should be implemented by the user in each concrete component type.

To properly handle interactions, any interaction should first be checked using should_invoke_for(), then turned into a component instance using loads(). Finally, callback() should be called on the component instance.

Parameters:

interaction (disnake.Interaction) – The interaction that caused this button to fire.

async as_ui_component() WrappedComponent[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:

disnake.ui.WrappedComponent

classmethod set_manager(_RichComponent__manager: ComponentManager | None) None[source]#

Set the component manager for this component type.

Parameters:

manager (typing.Optional[ComponentManager]) – The component manager to set on this component type.

class components.api.component.RichSelect[source]#

Bases: RichComponent, Protocol

Baseline protocol for Select-like components.

placeholder: str | None#

The placeholder of the component.

This shows when nothing is selected, or shows nothing if set to None.

min_values: int#

The minimum number of values the user must select.

This must lie between 1 and 25, inclusive.

max_values: int#

The maximum number of values the user may select.

This must lie between 1 and 25, inclusive.

disabled: bool#

Whether or not this button is disabled.

A disabled select is greyed out on discord, and cannot be used. Disabled selects can therefore not cause any interactions, either.

async as_ui_component() BaseSelect[Any, Any, None][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:

disnake.ui.WrappedComponent

class components.impl.component.base.ComponentBase[source]#

Bases: RichComponent, Protocol

Overarching base class for any kind of component.

classmethod set_manager(manager: ComponentManager | None, /) None[source]#

Set the component manager for this component type.

Parameters:

manager (typing.Optional[ComponentManager]) – The component manager to set on this component type.

classmethod should_invoke_for(interaction: Interaction, /) bool[source]#

Determine whether to fire this component’s callback.

This is done by determining whether the passed interaction has a custom id that matches that of this component type.

Parameters:

interaction (disnake.Interaction) – The interaction to check.

Returns:

Whether or not a component of this kind caused the interaction.

Return type:

bool

async dumps() str[source]#

Dump an instance of this class into a custom id string.

This ensures all special parameters are stored on the string in such a way that they can be losslessly loaded in the future by means of loads().

Returns:

The parsed custom id.

Return type:

str

async as_ui_component() WrappedComponent[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:

disnake.ui.WrappedComponent

class components.impl.component.select.BaseSelect[source]#

Bases: RichSelect, ComponentBase, Protocol

The base class of a disnake-ext-components selects.

For implementations, see RichStringSelect, RichUserSelect, RichRoleSelect, RichMentionableSelect, RichChannelSelect.

placeholder: str | None#

The placeholder of the component.

This shows when nothing is selected, or shows nothing if set to None.

min_values: int#

The minimum number of values the user must select.

This must lie between 1 and 25, inclusive.

max_values: int#

The maximum number of values the user may select.

This must lie between 1 and 25, inclusive.

disabled: bool#

Whether or not this button is disabled.

A disabled select is greyed out on discord, and cannot be used. Disabled selects can therefore not cause any interactions, either.

async classmethod loads(interaction: disnake.MessageInteraction, /) typing_extensions.Self[source]#

Load a fully-fledged component from an interaction.

The interaction’s custom id will be used to parse any special parameters.

Parameters:

interaction (disnake.Interaction) – The interaction from which to take the component data.

Returns:

An instance of this class with parameters extracted and parsed from the custom id.

Return type:

ComponentBase

async callback(_BaseSelect__inter: MessageInteraction) None[source]#

Run the component callback.

This should be implemented by the user in each concrete component type.

To properly handle interactions, any interaction should first be checked using should_invoke_for(), then turned into a component instance using loads(). Finally, callback() should be called on the component instance.

Parameters:

interaction (disnake.Interaction) – The interaction that caused this button to fire.