API documentation
Receive components’ event
- class components.ComponentsCog
A cog that receive and handles components’ event. You can load this cog as extension with:
bot.load_extension("discord.ext.components")
events
- on_button_click(com)
Fires when user clicked button.
- Parameters
com (
components.ButtonResponse
) – A response.
Fires when user selected menu.
- Parameters
com (
components.SelectMenuResponse
) – A response.
Respond components’ event
- class components.ButtonResponse(bot, data, state)
Represents a button response. Do not initialize this class directly.
- async defer_source(hidden=False)
ACK an interaction with DeferredChannelMessageWithSource(5). The user sees a loading state.
- Parameters
hidden (bool) – Hide interaction response or not.
- async defer_update()
ACK an interaction with DeferredUpdateMessage(6). The user doesn’t see a loading state.
- Parameters
hidden (bool) – Hide interaction response or not.
- property fired_by
Return
self.member
orself.user
.
- async send(content=None, *, embed=None, embeds=[], allowed_mentions=None, hidden=False, tts=False, components=[])
Responds interaction.
- Parameters
content...tts – Same as
discord.abc.Messageable.send
.hidden (bool) – Hide the message or not.
- class components.SelectMenuResponse(bot, data, state)
Represents a select menu response. Do not initialize this class directly.
- async defer_source(hidden=False)
ACK an interaction with DeferredChannelMessageWithSource(5). The user sees a loading state.
- Parameters
hidden (bool) – Hide interaction response or not.
- async defer_update()
ACK an interaction with DeferredUpdateMessage(6). The user doesn’t see a loading state.
- Parameters
hidden (bool) – Hide interaction response or not.
- property fired_by
Return
self.member
orself.user
.
- async send(content=None, *, embed=None, embeds=[], allowed_mentions=None, hidden=False, tts=False)
Responds interaction.
- Parameters
content...tts – Same as
discord.abc.Messageable.send
.hidden (bool) – Hide the message or not.
- property value
Return the first value of
values
orNone
.
Send messages with components
- async components.send(channel, content=None, *, tts=False, embed=None, embeds=None, file=None, files=None, delete_after=None, nonce=None, allowed_mentions=None, reference=None, mention_author=None, components=[])
Send message with components.
- Parameters
channel (discord.abc.Messageable) – Channel to send the message.
content..mention_author – Same as
discord.abc.Messageable.send
.components (list, optional) – Components to attach to the message. Specify 2D list if you want to use multi row components.
- Returns
Message was sent.
- Return type
Message
- async components.reply(target, *args, **kwargs)
An utility function for replying message.
Components
- class components.Button(label: str, custom_id: Optional[str] = None, style: Union[int, components.sender.ButtonType] = ButtonType.primary, url: Optional[str] = None, emoji: Optional[Union[discord.emoji.Emoji, str]] = None, enabled: bool = True, name: Optional[str] = None)
Represents a button in component.
- Parameters
label (str) – Label for the button.
custom_id (Optional[str]) – Custom id for the button.
style (Union[int, ButtonType]) – Style for the button.
url (Optional[str]) – URL for the button.
emoji (Union[Emoji, str]) – Emoji for the button.
enabled (bool) – Weather button is enabled or disabled.
- class components.SelectMenu(custom_id: Optional[str], options: List[components.sender.SelectOption], placeholder: Optional[str] = None, min_values: int = 1, max_values: int = 1)
Represents a select menu in component.
- Parameters
custom_id (Optional[str]) – Custom id for the select menu.
options (List[SelectOption]) – Options for the select menu.
placeholder (Optional[str]) – Placeholder for the select menu.
min_values (int) – Minimum number of items that must be chosen.
max_values (int) – Maximum number of items that must be chosen.
- class components.SelectOption(label: str, value: str, description: Optional[str] = None, emoji: Optional[Union[discord.emoji.Emoji, str]] = None, default: bool = False)
Represents a option for the select menu.
- Parameters
label (str) – Label for the option.
value (str) – Value for the option.
description (Optional[str]) – Description for the option.
emoji (Union[Emoji, str]) – Emoji for the option.
default (bool) – Weather option is default.