Utility Functions#
- interactions.utils.utils.autodefer(delay=2, ephemeral=False, edit_origin=False)[source]#
New in version 4.3.0.
A decorator that automatically defers a command if it did not respond within
delay
seconds.The structure of the decorator is:
@bot.command() @autodefer() # configurable async def command(ctx): await asyncio.sleep(5) await ctx.send("I'm awake now!")
- Parameters:
delay (Optional[Union[float, int]]) – The amount of time in seconds to wait before defering the command. Defaults to
2
seconds.ephemeral (Optional[bool]) – Whether the command is deferred ephemerally. Defaults to
False
.edit_origin (Optional[bool]) – Whether the command is deferred on origin. Defaults to
False
.
- Returns:
The inner function, for decorating.
- Return type:
- interactions.utils.utils.spread_to_rows(*components, max_in_row=5)[source]#
New in version 4.3.0.
A helper function that spreads components into
ActionRow
s.Example:
@bot.command() async def command(ctx): b1 = Button(style=1, custom_id="b1", label="b1") b2 = Button(style=1, custom_id="b2", label="b2") s1 = SelectMenu( custom_id="s1", options=[ SelectOption(label="1", value="1"), SelectOption(label="2", value="2"), ], ) b3 = Button(style=1, custom_id="b3", label="b3") b4 = Button(style=1, custom_id="b4", label="b4") await ctx.send("Components:", components=spread_to_rows(b1, b2, s1, b3, b4))
Note
You can only pass in
ActionRow
,Button
, andSelectMenu
, but in any order.- Parameters:
*components (Union[ActionRow, Button, SelectMenu]) – The components to spread.
max_in_row (Optional[int]) – The maximum number of components in a single row. Defaults to
5
.
- Returns:
List of Action rows
- Return type:
List[ActionRow]
- interactions.utils.utils.search_iterable(iterable, check=None, **kwargs)[source]#
New in version 4.3.0.
Searches through an iterable for items that: - Are True for the check, if one is given - Have attributes that match the keyword arguments (e.x. passing id=your_id will only return objects with that id)
- interactions.utils.utils.disable_components(components)[source]#
New in version 4.3.2.
Disables the given components.
- Parameters:
components (Union[List[Component], List[ActionRow], List[Button], List[SelectMenu], ActionRow, Component, Button, SelectMenu]) – The components to disable
- interactions.utils.utils.get_channel_history(http, channel, start_at=<interactions.MISSING>, reverse=False, check=None, maximum=inf)[source]#
New in version 4.3.2.
Gets the history of a channel.
- Parameters:
http (Union[HTTPClient, Client]) – The HTTPClient of the bot or your bot instance
channel (Union[int, str, Snowflake, Channel]) – The channel to get the history from
start_at (Optional[Union[int, str, Snowflake, Message]]) – The message to begin getting the history from
reverse (Optional[bool]) – Whether to only get newer message. Default False
check (Optional[Callable[[Message], Union[bool, Awaitable[bool]]]]) – A check to ignore specific messages
maximum (Optional[int]) – A set maximum of messages to get before stopping the iteration
- Returns:
An asynchronous iterator over the history of the channel
- Return type: