Package: dislash.py
dislash.pyAn extending library fordiscord.pythat allows to build awesome message components and slash commands.Table Of ContentsInstallationFeaturesExamplesCreating a slash commandCreating ButtonsCreating MenusCreating context menusLinksDownloadsInstallationRun any of these commands in terminal:pip install dislash.pypython -m pip install dislash.pyFeaturesSupports automatic registration of slash-commandsSupports manual and automatic shardingConvenient decorator-based interfaceWorks with discord.py <=1.7.3, >=2.0.0aExamples💡 This library requiresdiscord.py.Creating a slash commandfromdiscord.extimportcommandsfromdislashimportInteractionClientbot=commands.Bot(command_prefix="!")slash=InteractionClient(client)test_guilds=[12345,98765]@slash.command(name="hello",# Defaults to function namedescription="Says hello",guild_ids=test_guilds# If not specified, the command is registered globally# Global registration takes up to 1 hour)asyncdefhello(inter):awaitinter.reply("Hello!")bot.run("BOT_TOKEN")Creating buttonsThis example shows how to send a message with buttons.fromdiscord.extimportcommandsfromdislashimportInteractionClient,ActionRow,Button,ButtonStylebot=commands.Bot(command_prefix="!")slash=InteractionClient(bot)@bot.command()asyncdeftest(ctx):# Make a row of buttonsrow_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 buttonsmsg=awaitctx.send("This message has buttons!",components=[row_of_buttons])# Wait for someone to click on themdefcheck(inter):returninter.message.id==msg.idinter=awaitctx.wait_for_button_click(check)# Send what you receivedbutton_text=inter.clicked_button.labelawaitinter.reply(f"Button:{button_text}")bot.run("BOT_TOKEN")Creating menusThis example shows how to send a message with a menu.fromdiscord.extimportcommandsfromdislashimportInteractionClient,SelectMenu,SelectOptionbot=commands.Bot(command_prefix="!")slash=InteractionClient(bot)@bot.command()asyncdeftest(ctx):msg=awaitctx.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 itinter=awaitmsg.wait_for_dropdown()# Send what you receivedlabels=[option.labelforoptionininter.select_menu.selected_options]awaitinter.reply(f"Options:{', '.join(labels)}")bot.run("BOT_TOKEN")Creating context menusThis example shows how to create context menus and interact with them.fromdiscord.extimportcommandsfromdislashimportInteractionClientbot=commands.Bot(command_prefix="!")inter_client=InteractionClient(bot)@inter_client.user_command(name="Press me")asyncdefpress_me(inter):# User commands are visible in user context menus# They can be global or per guild, just like slash commandsawaitinter.respond("Hello there!")@inter_client.message_command(name="Resend")asyncdefresend(inter):# Message commands are visible in message context menus# inter is instance of ContextMenuInteractionawaitinter.respond(inter.message.content)bot.run("BOT_TOKEN")LinksDocumentationPyPiOur DiscordDownloads