Components#

Button#

class components.RichButton[source]

Bases: RichButton, ComponentBase, Protocol

The default implementation of a disnake-ext-components button.

This works similar to a dataclass, but with some extra things to take into account.

First and foremost, there are class variables for label, style, emoji and disabled. These set the corresponding attributes on the button class when they are sent to discord, and are meant to be overwritten by the user.

Next, fields can be defined similarly to dataclasses, by means of a name, a type annotation, and an optional components.field() to set the default or a custom parser.

Classes created in this way have auto-generated slots and an auto-generated __init__. The init-signature contains all the custom id fields as keyword-only arguments.

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

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(_RichButton__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.

Select Menu#

class components.RichStringSelect[source]#

Bases: BaseSelect, Protocol

The default implementation of a disnake-ext-components string select.

This works similar to a dataclass, but with some extra things to take into account.

First and foremost, there are class variables for placeholder, min_values, max_values, disabled, and:attr:options. These set the corresponding attributes on the select class when they are sent to discord, and are meant to be overwritten by the user.

Fields can be defined similarly to dataclasses, by means of a name, a type annotation, and an optional components.field() to set the default or a custom parser. The options field specifically is designated with components.options() instead.

Classes created in this way have auto-generated slots and an auto-generated __init__. The init-signature contains all the custom id fields as keyword-only arguments.

async as_ui_component() StringSelect[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.RichUserSelect[source]#

Bases: BaseSelect, Protocol

The default implementation of a disnake-ext-components user select.

This works similar to a dataclass, but with some extra things to take into account.

First and foremost, there are class variables for placeholder, min_values, max_values, disabled. These set the corresponding attributes on the select class when they are sent to discord, and are meant to be overwritten by the user.

Fields can be defined similarly to dataclasses, by means of a name, a type annotation, and an optional components.field() to set the default or a custom parser. The options field specifically is designated with components.options() instead.

Classes created in this way have auto-generated slots and an auto-generated __init__. The init-signature contains all the custom id fields as keyword-only arguments.

async as_ui_component() UserSelect[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.RichRoleSelect[source]#

Bases: BaseSelect, Protocol

The default implementation of a disnake-ext-components role select.

This works similar to a dataclass, but with some extra things to take into account.

First and foremost, there are class variables for placeholder, min_values, max_values, disabled. These set the corresponding attributes on the select class when they are sent to discord, and are meant to be overwritten by the user.

Fields can be defined similarly to dataclasses, by means of a name, a type annotation, and an optional components.field() to set the default or a custom parser. The options field specifically is designated with components.options() instead.

Classes created in this way have auto-generated slots and an auto-generated __init__. The init-signature contains all the custom id fields as keyword-only arguments.

async as_ui_component() RoleSelect[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.RichMentionableSelect[source]#

Bases: BaseSelect, Protocol

The default implementation of a disnake-ext-components mentionable select.

This works similar to a dataclass, but with some extra things to take into account.

First and foremost, there are class variables for placeholder, min_values, max_values, disabled. These set the corresponding attributes on the select class when they are sent to discord, and are meant to be overwritten by the user.

Fields can be defined similarly to dataclasses, by means of a name, a type annotation, and an optional components.field() to set the default or a custom parser. The options field specifically is designated with components.options() instead.

Classes created in this way have auto-generated slots and an auto-generated __init__. The init-signature contains all the custom id fields as keyword-only arguments.

async as_ui_component() MentionableSelect[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.RichChannelSelect[source]#

Bases: BaseSelect, Protocol

The default implementation of a disnake-ext-components channel select.

This works similar to a dataclass, but with some extra things to take into account.

First and foremost, there are class variables for channel_types, placeholder, min_values, max_values, disabled. These set the corresponding attributes on the select class when they are sent to discord, and are meant to be overwritten by the user.

Fields can be defined similarly to dataclasses, by means of a name, a type annotation, and an optional components.field() to set the default or a custom parser. The options field specifically is designated with components.options() instead.

Classes created in this way have auto-generated slots and an auto-generated __init__. The init-signature contains all the custom id fields as keyword-only arguments.

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