Component for discord.py
Project description
dpy-components
This lib adds components support for discord.py.
Please note this is beta yet.
Example
import os
from discord.ext import commands, components
bot = commands.Bot("c ")
bot.load_extension("discord.ext.components")
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@bot.command()
async def test(ctx, button_label, hidden: bool):
await components.send(ctx, "Click this", components=[components.Button(button_label, name="button1")])
cmp = await bot.wait_for("button_click", check=lambda c: c.name == "button1")
await cmp.send(f"You clicked {button_label}.", hidden=hidden)
bot.run(os.getenv("token"))
Reference
components.send
|components.sender.send
This function is a coroutine. Send message with components.
components.send(channel: discord.abc.Messageable, content=None, *, tts=False, embed=None, file=None,
files=None, delete_after=None, nonce=None,
allowed_mentions=None, reference=None,
mention_author=None, components=[])
channnel
: Channel to send the message.
content
..mention_author
: Same as discord.abc.Messageable.send
.
components
: Components to attach to the message.
If you want to use multi row components, please specify 2D list.
components.reply
|components.sender.reply
This function is a coroutine.
An utility function for replying message.
Same as:
await send(target.channel, *args, reference=target.to_reference(), **kwargs)
components.Button
Represents a button in component.
label
: Label for the button.
custom_id
|name
: Custom id for the button.
url
: URL for the button.
style
: Style for the button.
Pass values of Button Styles.
emoji
: Emoji for the button.
enabled
: Whether the button is enabled.
Properties
.disabled
: Same as not self.enabled
.
on_button_click(cmp: ButtonResponse)
Fires when user clicked button.
ButtonResponse
Represents a button response.
Do not initialize this class directly.
id
: ID of the interaction.
application_id
: Application ID of the interaction.
guild
: Guild of the interaction.
channel
: Channel of the interaction.
message
: Message of the interaction.
member
: Member who pressed the button.
token
: Token of the interaction.
custom_id
|name
: Custom ID of the button.
ButtonResponse.send
This function is a coroutine.
Responds interaction.
ButtonResponse.send(
content=None, *,
embed=None,
embeds=[],
allowed_mentions=None,
tts=False,
hidden=False
)
content
...tts
: Same as discord.abc.Messageable.send
.
hidden
: Hide the message or not.
ButtonResponse.defer_source
This function is a coroutine.
ACK an interaction with DeferredChannelMessageWithSource(5).
The user sees a loading state.
ButtonResponse.defer_update
This function is a coroutine.
ACK an interaction with DeferredUpdateMessage(6).
The user doesn't see a loading state.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for dpy_components-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bf6200acb7ec2dd554916d278e5036256ff32456ce75e1fdc9d4c54adc6cbff |
|
MD5 | 3f1bf07ae7d41e03395292e6c728d8b5 |
|
BLAKE2b-256 | cdcdbc861ed7a466d4e038b9f3ea80413c459fb2e4a05fb4507f51df1f452dd2 |