Package: dslash
DSlashTHIS PROJECT IS NO LONGER MAINTAINEDDanny has returned from a break, andDiscord.pyis now being maintained again, with support for slash commands. Nextcord also
now has built-in support for slash commands. For new projects, you should use
one of these options (or another).Dslash will continue to receive minimal updates to keep it working, at least
for the near future, but it will not receive support for new features.One change Discord has made since this library stopped being maintained was
to remove support for bots configuring permissions for their own commands. In
order to avoid breaking bots, Dslash still allows permissions to be
configured as before, but will now ignore them. Theallow_roles,allow_users,disallow_roles,disallow_users,global_permissionsandguild_permissionswrappers, as well as thedefault_permissionandpermissionsparameters are all deprecated and should not be used.A library which supplementsNextcord(a fork of Discord.py) by adding support for slash commands.Documentation is still a work in progress, and the library should currently be
considered unstable.You can install it using pip, eg.pip install dslash.ExampleimportloggingimportrandomimporttypingfromdslashimportChoices,CommandClient,CommandGroup,CommandSubGroup,subcommandfromnextcordimportEmbed,Interaction,Member,Role,AttachmentGUILD_ID=...TOKEN=...logging.basicConfig(level=logging.INFO)client=CommandClient(guild_id=GUILD_ID)@client.eventasyncdefon_ready():print(f"Logged in as{client.user}.")@client.command()asyncdefroll(interaction:Interaction,sides:typing.Optional[int]):"""Roll a dice.:param sides: How many sides (default 6)."""value=random.randint(1,sidesor6)awaitinteraction.response.send_message(f"You got:{value}")@client.groupclassImages(CommandGroup):"""Cute image commands."""@subcommand()asyncdefcat(self,interaction:Interaction):"""Get a cat image."""awaitinteraction.response.send_message(embed=Embed().set_image(url="https://cataas.com/cat"))@subcommand()asyncdefdog(self,interaction:Interaction):"""Get a dog image."""awaitinteraction.response.send_message(embed=Embed().set_image(url="https://placedog.net/500?random"))@subcommand(name="any")asyncdefany_(self,interaction:Interaction):"""Get any random image."""awaitinteraction.response.send_message(embed=Embed().set_image(url="https://picsum.photos/600"))@subcommand()asyncdefupload(self,interaction:Interaction,image:Attachment):"""Upload a new cute image."""print(f"Uploading{image.proxy_url!r}...")awaitinteraction.response.send_message("All done!")@client.groupclassAdmin(CommandGroup):"""Admin-only commands."""classRoles(CommandSubGroup):"""Commands to manage roles."""@subcommand(name="del")asyncdefdel_(self,interaction:Interaction,role:Role):"""Delete a role.:param role: The role to delete."""awaitrole.delete()awaitinteraction.response.send_message("Deleted the role.",ephemeral=True)@client.command()asyncdefban(interaction:Interaction,user:Member):"""Ban a user.:param user: The user to ban."""awaituser.ban()awaitinteraction.response.send_message("Banned the user.",ephemeral=True)classRPSChoices(Choices):rock="Rock"paper="Paper"scissors="Scissors"gun="Gun"@client.command()asyncdefrps(interaction:Interaction,choice:RPSChoices):"""Play rock, paper, scissors.:param choice: Your choice."""ifchoice==RPSChoices.gun:awaitinteraction.response.send_message("That's cheating!")else:awaitinteraction.response.send_message(f"You picked{choice.name}.")client.run(TOKEN)DevelopmentAs well as Python 3.9+, this project requires Poetry for development.Click this link for installation instructions,
or:*nix (Linux/MacOS)curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -Windows Powershell(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python -Once you have Poetry installed:Create a virtual environment:poetry shellInstall dependencies:poetry installThe following commands are then available:poe format- Run auto-formatting and linting.Prefix these withpoetry runif outside of the Poetry shell.