Warning
This library is no longer maintained in favor of disnake. Disnake is an updated version of discord.py with the latest API features implemented. The syntax for slash commands is very convenient so we really recommend using disnake if you're planning to switch to slash commands before April 2022.
If you have any questions, join Our Discord Server
dislash.py

An extending library for discord.py that allows to build awesome message components and slash commands.
Note about the future of discord.py
Since discord.py will no longer stay up to date, we decided to create a fork: disnake. It has all features of dpy 2.0 + application commands.
Table Of Contents
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="!")
inter_client = InteractionClient(bot, test_guilds=[12345, 98765])
@inter_client.slash_command(
name="hello",
description="Says hello",
guild_ids=test_guilds
)
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="!")
inter_client = InteractionClient(bot)
@bot.command()
async def test(ctx):
row_of_buttons = ActionRow(
Button(
style=ButtonStyle.green,
label="Green button",
custom_id="green"
),
Button(
style=ButtonStyle.red,
label="Red button",
custom_id="red"
)
)
msg = await ctx.send(
"This message has buttons!",
components=[row_of_buttons]
)
def check(inter):
return inter.message.id == msg.id
inter = await ctx.wait_for_button_click(check)
button_text = inter.clicked_button.label
await inter.reply(f"Button: {button_text}")
bot.run("BOT_TOKEN")
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="!")
inter_client = 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")
]
)
]
)
inter = await msg.wait_for_dropdown()
labels = [option.label for option in inter.select_menu.selected_options]
await inter.reply(f"Options: {', '.join(labels)}")
bot.run("BOT_TOKEN")
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):
await inter.respond("Hello there!")
@inter_client.message_command(name="Resend")
async def resend(inter):
await inter.respond(inter.message.content)
bot.run("BOT_TOKEN")
Links
Downloads
