A discord button handler for discord.py
Project description
https://pypi.org/project/discord-message-components/
Introduction
This is a discord.py message component extension made by 404kuso and RedstoneZockt, which you can use until discord.py v2.0 is out
We got some features for you like send buttons, send select menus, receive a press or selection and edit messages with buttons and selection menus and everything is compatible with discord.py
Docs
You can read the docs here
The docs can include some typos or issues, if so, plz let me know
License
This project is under MIT License
Example
Here is a small example, that will respond to the pressed button with the content of it or will respond with the content and value of the selected element in an select menu
import discord
from discord.ext import commands
from discord_message_components import *
client = commands.Bot(" ")
client.components = Components(client)
@client.listen("ready")
async def on_ready():
print("ready")
@client.listen('on_message')
async def on_message(message):
if message.content == "!btn":
await client.components.send(message.channel, "Ayo this is really cool, right?", components=[
Button(custom_id="yes", label="yes!", color="green", emoji="😁"),
Button(custom_id="no", label="no", emoji="😐", new_line=True)]
)
elif message.content == "!sel":
await client.components.send(message.channel, "This is really cool too, right?", components=[
SelectMenu(custom_id="select_menus_cool", options=[
SelectMenuOption(label="yes", value=1, description="I think this is really cool"),
SelectMenuOption(label="no", value=2, description="Nah this is really boring"),
SelectMenuOption(label="i don't really know", value=3, emoji="😐")
], max_values = 3, default=2)
])
elif message.content == "!mix":
print("mix")
await client.components.send(message.channel,
content="You can even mix things",
embed=discord.Embed(description="nice!"),
components=[
LinkButton("https://discord.com", "discord is really nice"),
SelectMenu(custom_id="custom_ids", options=[
SelectMenuOption("yeess", 4),
SelectMenuOption("hello_there", 5, "I really love it")
], min_values=1, placeholder="I like everything"),
Button("again_a_custom_id", "niceu diceu"),
Button("cool", "lookin good", color="green", new_line=True),
Button("hehe", "here too", color="red")
])
@client.listen('on_button_press')
async def on_button(btn: PressedButton, msg: ResponseMessage):
await msg.respond(btn.member.mention + ", you pressed on " + btn.content + " with the custom id of " + btn.custom_id)
@client.listen('on_menu_select')
async def on_select(menu: SelectedMenu, msg: ResponseMessage):
await msg.respond(menu.member.mention + ", you selected " + ', '.join([x.content for x in menu.values]) + " on the menu with the custom id " + menu.custom_id)
client.run(token)
Changelog
-
1.1.2
Fixed
- Small code fixes
-
1.1.1
Added
- Message.edit()
You can now edit messages with button support
- Message.edit()
-
1.1.0
Changed
- Major changes to request code, now using the client's request
ResponseMessage.acknowledge()
->ResponseMessage.defer()
Changed the name of the function + changed
ResponseMessage.acknowledged
->ResponseMessage.deferred
ResponseMessage.defer()
=>await ResponseMessage.defer()
defer
(acknowledge
) is now async and needs to be awaited
Added
- hidden responses
You can now send responses only visible to the user
Fixed
ResponseMessage.respond()
Now doesn't show a failed interaction
-
1.0.5
Fixed
ResponseMessage.respond()
responding now doesn't fail after sending the message, it will now defer the interaction by it self if not already deferred and then send the message
-
1.0.4
Added
ResponseMessage.acknowledged
Whether the message was acknowledged with the
ResponseMessage.acknowledged()
function
Changed
-
ResponseMessage.respond()
=>await ResponseMessage.respond()
respond() function is now async and needs to be awaited
-
ResponseMessage.respond() -> None
=>ResponseMessage.respond() -> Message or None
respond() now returns the sent message or None if ninjaMode is true
-
1.0.3
Added
Button.hash
Buttons have now a custom hash property, generated by the discord api
Contact
You can contact us on discord
- RedstoneZockt#2510
- ! DaKuso#4214
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 Distribution
Built Distribution
Hashes for discord-message-components-1.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c65a298723dce5f8e2df8e9ed5cad4524652ad34bede8c04e62116d6b3cdf9b7 |
|
MD5 | 579f639ccca6afa5143adc5404cfd888 |
|
BLAKE2b-256 | 58fa1c964d7df7f287527acf2625e7715a58cd8b4690c343270cb5968a218302 |
Hashes for discord_message_components-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39e8bb82e201eef9e32531ab65340e1598a8f7af8b6f238ddbf218b43e560b0e |
|
MD5 | d41dad013ec8fbbb7939df01c1ab3df0 |
|
BLAKE2b-256 | dbd0a0ef641e855566a6149ce7ba5144796d3d918441ce62509173b405084f63 |