A python wrapper for discord slash commands and message components.
Project description
dislash.py
An extending library for discord.py that allows to build awesome slash-commands and message components.
📄 Slash commands is a new discord API feature that allows to build user-friendly commands. Once "/
" is pressed on keyboard, the entire list of slash-commands pops up. The list includes hints and short descriptions which make exploring your bot much easier.
Installation
Run any of these commands in terminal:
pip install dislash.py
python -m pip install dislash.py
Features
- Supports automatic registration of slash-commands
- Supports manual and automatic sharding
- Convenient decorator-based interface
- OOP-based slash-command and button constructor
Examples
💡 This library requires discord.py.
Creating a slash-command
In this example registration is automatic. If you want to register slash-commands separately, see docs.
from discord.ext import commands
from dislash import slash_commands
from dislash.interactions import *
client = commands.Bot(command_prefix="!")
slash = slash_commands.SlashClient(client)
test_guilds = [12345, 98765]
@slash.command(
name="hello", # Defaults to function name
description="Says hello",
guild_ids=test_guilds # If not specified, the command is registered globally
# Global registration takes up to 1 hour
)
async def hello(inter):
await inter.reply("Hello!")
client.run("BOT_TOKEN")
Creating buttons
This example shows how to send a message with buttons.
from discord.ext import commands
from dislash.slash_commands import *
from dislash.interactions import *
client = commands.Bot(command_prefix="!")
slash = SlashClient(client)
@client.command()
async def test(ctx):
# Make a row of buttons
row_of_buttons = ActionRow(
Button(
style=ButtonStyle.green,
label="Green button",
custom_id="green"
),
Button(
style=ButtonStyle.red,
label="Red button",
custom_id="red"
)
)
# Send a message with buttons
msg = await ctx.send(
"This message has buttons!",
components=[row_of_buttons]
)
# Wait for someone to click on them
def check(inter):
return inter.message.id == msg.id
inter = await ctx.wait_for_button_click(check)
# Send what you received
button_text = inter.clicked_button.label
await inter.reply(f"Button: {button_text}")
client.run("BOT_TOKEN")
Links
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 dislash.py-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34fdddddade131d4cb1840495e57d35c516be1f9ff3b8180a6b0d82d98a3cc77 |
|
MD5 | 1a9d9be2b3a28075d8c9fe3595567fb5 |
|
BLAKE2b-256 | 3a102598fc1dd5519b29f22095d95cc4f233870ddad512d5061b7eea37268c3a |