A python wrapper for message components and application commands.
Project description
dislash.py
An extending library for discord.py that allows to build awesome message components and slash commands.
Table Of Contents
- Installation
- Features
- Examples
- Creating a slash command
- Creating Buttons
- Creating Menus
- Creating context menus
- Links
- Downloads
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
- Works with discord.py <=1.7.3, >=2.0.0a
Examples
💡 This library requires discord.py.
Creating a slash command
from discord.ext import commands
from dislash import InteractionClient
bot = commands.Bot(command_prefix="!")
slash = InteractionClient(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!")
bot.run("BOT_TOKEN")
Creating buttons
This example shows how to send a message with buttons.
from discord.ext import commands
from dislash import InteractionClient, ActionRow, Button, ButtonStyle
bot = commands.Bot(command_prefix="!")
slash = InteractionClient(bot)
@bot.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}")
bot.run("BOT_TOKEN")
Creating menus
This example shows how to send a message with a menu.
from discord.ext import commands
from dislash import InteractionClient, SelectMenu, SelectOption
bot = commands.Bot(command_prefix="!")
slash = InteractionClient(bot)
@bot.command()
async def test(ctx):
msg = await ctx.send(
"This message has a select menu!",
components=[
SelectMenu(
custom_id="test",
placeholder="Choose up to 2 options",
max_values=2,
options=[
SelectOption("Option 1", "value 1"),
SelectOption("Option 2", "value 2"),
SelectOption("Option 3", "value 3")
]
)
]
)
# Wait for someone to click on it
inter = await msg.wait_for_dropdown()
# Send what you received
labels = [option.label for option in inter.select_menu.selected_options]
await inter.reply(f"Options: {', '.join(labels)}")
bot.run("BOT_TOKEN")
Creating context menus
This example shows how to create context menus and interact with them.
from discord.ext import commands
from dislash import InteractionClient
bot = commands.Bot(command_prefix="!")
inter_client = InteractionClient(bot)
@inter_client.user_command(name="Press me")
async def press_me(inter):
# User commands are visible in user context menus
# They can be global or per guild, just like slash commands
await inter.respond("Hello there!")
@inter_client.message_command(name="Resend")
async def resend(inter):
# Message commands are visible in message context menus
# inter is instance of ContextMenuInteraction
await inter.respond(inter.message.content)
bot.run("BOT_TOKEN")
Links
Downloads
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dislash.py-1.4.9.tar.gz.
File metadata
- Download URL: dislash.py-1.4.9.tar.gz
- Upload date:
- Size: 41.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7940bcf167b1b213b8e2cf0dbf54c3e1a7a5c95121bf698dbb72bb82f7a48feb
|
|
| MD5 |
5cbf43d4301de56b54f87a94c6d84976
|
|
| BLAKE2b-256 |
3366285edec0f6f4865b5ff0cfc8de0f2df31e017c56f9dd03f9daa6671b7f65
|
File details
Details for the file dislash.py-1.4.9-py3-none-any.whl.
File metadata
- Download URL: dislash.py-1.4.9-py3-none-any.whl
- Upload date:
- Size: 74.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
effb7093ab66c621970439600c50ef87117e34f5fef5260b0eea76b62b0f96ad
|
|
| MD5 |
ee7ffa1211755aa171af4ff4a31ee3fd
|
|
| BLAKE2b-256 |
082553ab55bab1871cd6254089f49c9222e0340ec2beb11086ce9153cbae1081
|