discord_slash.utils.manage_components module¶
- discord_slash.utils.manage_components.create_actionrow(*components: dict) dict ¶
Creates an ActionRow for message components.
- Parameters
components – Components to go within the ActionRow.
- Returns
dict
- discord_slash.utils.manage_components.spread_to_rows(*components, max_in_row=5) List[dict] ¶
A helper function that spreads your components into
actionrows
of a set size- Parameters
- Returns
list
Note
An action_row can only have a maximum of 5 items in it
- discord_slash.utils.manage_components.emoji_to_dict(emoji: Union[discord.emoji.Emoji, discord.partial_emoji.PartialEmoji, str]) dict ¶
Converts a default or custom emoji into a partial emoji dict.
- Parameters
emoji (Union[discord.Emoji, discord.PartialEmoji, str]) – The emoji to convert.
- discord_slash.utils.manage_components.create_button(style: Union[discord_slash.model.ButtonStyle, int], label: Optional[str] = None, emoji: Optional[Union[discord.emoji.Emoji, discord.partial_emoji.PartialEmoji, str]] = None, custom_id: Optional[str] = None, url: Optional[str] = None, disabled: bool = False) dict ¶
Creates a button component for use with the
components
field. Must be used within anactionRow
to be used (seecreate_actionrow()
).Note
At least a label or emoji is required for a button. You can have both, but not neither of them.
- Parameters
style (Union[ButtonStyle, int]) – Style of the button. Refer to
ButtonStyle
.label (Optional[str]) – The label of the button.
emoji (Union[discord.Emoji, discord.PartialEmoji, dict]) – The emoji of the button.
custom_id (Optional[str]) – The custom_id of the button. Needed for non-link buttons.
url (Optional[str]) – The URL of the button. Needed for link buttons.
disabled (bool) – Whether the button is disabled or not. Defaults to False.
- Returns
- discord_slash.utils.manage_components.create_select_option(label: str, value: str, emoji=None, description: Optional[str] = None, default: bool = False)¶
Creates an option for select components.
- Parameters
label – The user-facing name of the option that will be displayed in discord client.
value – The value that the bot will receive when this option is selected.
emoji – The emoji of the option.
description – An additional description of the option.
default – Whether or not this is the default option.
- discord_slash.utils.manage_components.create_select(options: List[dict], custom_id: Optional[str] = None, placeholder: Optional[str] = None, min_values: Optional[int] = None, max_values: Optional[int] = None, disabled: bool = False)¶
Creates a select (dropdown) component for use with the
components
field. Must be inside an ActionRow to be used (seecreate_actionrow()
).- Parameters
options – The choices the user can pick from
custom_id – A custom identifier, like buttons
placeholder – Custom placeholder text if nothing is selected
min_values – The minimum number of items that must be chosen
max_values – The maximum number of items that can be chosen
disabled – Disables this component. Defaults to
False
.
- discord_slash.utils.manage_components.get_components_ids(component: Union[str, dict, list]) Iterator[str] ¶
Returns generator with the
custom_id
of a component or list of components.- Parameters
component – Custom ID or component dict (actionrow or button) or list of the two.
- Returns
typing.Iterator[str]
- discord_slash.utils.manage_components.get_messages_ids(message: Union[int, discord.message.Message, list]) Iterator[int] ¶
Returns generator with the
id
of message or list messages.- Parameters
message – message ID or message object or list of previous two.
- Returns
typing.Iterator[int]
- async discord_slash.utils.manage_components.wait_for_component(client: discord.client.Client, messages: Optional[Union[int, discord.message.Message, list]] = None, components: Optional[Union[str, dict, list]] = None, check=None, timeout=None) discord_slash.context.ComponentContext ¶
Helper function - wrapper around ‘client.wait_for(“component”, …)’
Waits for a component interaction. Only accepts interactions based on the custom ID of the component or/and message ID, and optionally a check function.
- Parameters
client (
discord.Client
) – The client/bot object.messages (Union[discord.Message, int, list]) – The message object to check for, or the message ID or list of previous two.
components (Union[str, dict, list]) – Custom ID to check for, or component dict (actionrow or button) or list of previous two.
check – Optional check function. Must take a ComponentContext as the first parameter.
timeout – The number of seconds to wait before timing out and raising
asyncio.TimeoutError
.
- Raises