An unofficial library for Discord components. (on development)
pip install --upgrade discord-components
from discord import Client
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType
bot = Client()
@bot.event
async def on_ready():
DiscordComponents(bot)
@bot.event
async def on_message(msg):
if msg.author.bot:
return
await msg.channel.send(
"Content",
components=[
Button(style=ButtonStyle.blue, label="Blue"),
Button(style=ButtonStyle.red, label="Red"),
Button(style=ButtonStyle.URL, label="url", url="https://example.org"),
],
)
res = await bot.wait_for("button_click")
if res.channel == msg.channel:
await res.respond(
type=InteractionType.ChannelMessageWithSource,
content=f'{res.component.label} clicked'
)
bot.run("token")
The docs can contain lot of spelling mistakes, grammar errors so if there is a problem please create an issue!
- Send, edit Discord components.
- Get components interact event!
- Supports discord.py command extension.