# DSlash
![Version: 0.6.4](https://img.shields.io/badge/Version-0.6.4-red?style=flat-square)
[![Code Style: black](https://img.shields.io/badge/Code%20Style-black-black?style=flat-square)](https://github.com/psf/black)
[![License: MIT](https://img.shields.io/badge/License-MIT-orange?style=flat-square)](./LICENSE)
[![PyPI: dslash](https://img.shields.io/badge/PyPI-dslash-green?style=flat-square)](https://pypi.org/project/dslash)
![Python: ^3.9](https://img.shields.io/badge/python-%5E3.9-blue?style=flat-square)
> **THIS PROJECT IS NO LONGER MAINTAINED**
>
> Danny has returned from a break, and [Discord.py](https://github.com/rapptz/discord.py)
> is 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. The `allow_roles`,
> `allow_users`, `disallow_roles`, `disallow_users`, `global_permissions` and
> `guild_permissions` wrappers, as well as the `default_permission` and
> `permissions` parameters are all deprecated and should not be used.
A library which supplements [Nextcord](https://github.com/nextcord/nextcord)
(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`.
## Example
```python
import logging
import random
import typing
from dslash import Choices, CommandClient, CommandGroup, CommandSubGroup, subcommand
from nextcord import Embed, Interaction, Member, Role, Attachment
GUILD_ID = ...
TOKEN = ...
logging.basicConfig(level=logging.INFO)
client = CommandClient(guild_id=GUILD_ID)
@client.event
async def on_ready():
print(f"Logged in as {client.user}.")
@client.command()
async def roll(interaction: Interaction, sides: typing.Optional[int]):
"""Roll a dice.
:param sides: How many sides (default 6).
"""
value = random.randint(1, sides or 6)
await interaction.response.send_message(f"You got: {value}")
@client.group
class Images(CommandGroup):
"""Cute image commands."""
@subcommand()
async def cat(self, interaction: Interaction):
"""Get a cat image."""
await interaction.response.send_message(
embed=Embed().set_image(url="https://cataas.com/cat")
)
@subcommand()
async def dog(self, interaction: Interaction):
"""Get a dog image."""
await interaction.response.send_message(
embed=Embed().set_image(url="https://placedog.net/500?random")
)
@subcommand(name="any")
async def any_(self, interaction: Interaction):
"""Get any random image."""
await interaction.response.send_message(
embed=Embed().set_image(url="https://picsum.photos/600")
)
@subcommand()
async def upload(self, interaction: Interaction, image: Attachment):
"""Upload a new cute image."""
print(f"Uploading {image.proxy_url!r}...")
await interaction.response.send_message("All done!")
@client.group
class Admin(CommandGroup):
"""Admin-only commands."""
class Roles(CommandSubGroup):
"""Commands to manage roles."""
@subcommand(name="del")
async def del_(self, interaction: Interaction, role: Role):
"""Delete a role.
:param role: The role to delete.
"""
await role.delete()
await interaction.response.send_message("Deleted the role.", ephemeral=True)
@client.command()
async def ban(interaction: Interaction, user: Member):
"""Ban a user.
:param user: The user to ban.
"""
await user.ban()
await interaction.response.send_message("Banned the user.", ephemeral=True)
class RPSChoices(Choices):
rock = "Rock"
paper = "Paper"
scissors = "Scissors"
gun = "Gun"
@client.command()
async def rps(interaction: Interaction, choice: RPSChoices):
"""Play rock, paper, scissors.
:param choice: Your choice.
"""
if choice == RPSChoices.gun:
await interaction.response.send_message("That's cheating!")
else:
await interaction.response.send_message(f"You picked {choice.name}.")
client.run(TOKEN)
```
## Development
As well as Python 3.9+, this project requires Poetry for development.
[Click this link for installation instructions](https://python-poetry.org/docs/master/#installation),
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:
1. **Create a virtual environment:** `poetry shell`
2. **Install dependencies:** `poetry install`
The following commands are then available:
- `poe format` - Run auto-formatting and linting.
Prefix these with `poetry run` if outside of the Poetry shell.
Raw data
{
"_id": null,
"home_page": "https://github.com/artemis21/dslash",
"name": "dslash",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "discord,discord.py,nextcord,slash commands,extension",
"author": "Artemis",
"author_email": "me@arty.li",
"download_url": "https://files.pythonhosted.org/packages/e4/1a/0fd2e4d860d291f771e308928cd9654447e3b08caf095d837f4d15956ce6/dslash-0.6.4.tar.gz",
"platform": null,
"description": "# DSlash\n\n![Version: 0.6.4](https://img.shields.io/badge/Version-0.6.4-red?style=flat-square)\n[![Code Style: black](https://img.shields.io/badge/Code%20Style-black-black?style=flat-square)](https://github.com/psf/black)\n[![License: MIT](https://img.shields.io/badge/License-MIT-orange?style=flat-square)](./LICENSE)\n[![PyPI: dslash](https://img.shields.io/badge/PyPI-dslash-green?style=flat-square)](https://pypi.org/project/dslash)\n![Python: ^3.9](https://img.shields.io/badge/python-%5E3.9-blue?style=flat-square)\n\n> **THIS PROJECT IS NO LONGER MAINTAINED**\n>\n> Danny has returned from a break, and [Discord.py](https://github.com/rapptz/discord.py)\n> is now being maintained again, with support for slash commands. Nextcord also\n> now has built-in support for slash commands. For new projects, you should use\n> one of these options (or another).\n>\n> Dslash will continue to receive minimal updates to keep it working, at least\n> for the near future, but it will not receive support for new features.\n>\n> One change Discord has made since this library stopped being maintained was\n> to remove support for bots configuring permissions for their own commands. In\n> order to avoid breaking bots, Dslash still allows permissions to be\n> configured as before, but will now ignore them. The `allow_roles`,\n> `allow_users`, `disallow_roles`, `disallow_users`, `global_permissions` and\n> `guild_permissions` wrappers, as well as the `default_permission` and\n> `permissions` parameters are all deprecated and should not be used.\n\nA library which supplements [Nextcord](https://github.com/nextcord/nextcord)\n(a fork of Discord.py) by adding support for slash commands.\n\nDocumentation is still a work in progress, and the library should currently be\nconsidered unstable.\n\nYou can install it using pip, eg. `pip install dslash`.\n\n## Example\n\n```python\nimport logging\nimport random\nimport typing\n\nfrom dslash import Choices, CommandClient, CommandGroup, CommandSubGroup, subcommand\nfrom nextcord import Embed, Interaction, Member, Role, Attachment\n\nGUILD_ID = ...\nTOKEN = ...\n\nlogging.basicConfig(level=logging.INFO)\nclient = CommandClient(guild_id=GUILD_ID)\n\n\n@client.event\nasync def on_ready():\n print(f\"Logged in as {client.user}.\")\n\n\n@client.command()\nasync def roll(interaction: Interaction, sides: typing.Optional[int]):\n \"\"\"Roll a dice.\n\n :param sides: How many sides (default 6).\n \"\"\"\n value = random.randint(1, sides or 6)\n await interaction.response.send_message(f\"You got: {value}\")\n\n\n@client.group\nclass Images(CommandGroup):\n \"\"\"Cute image commands.\"\"\"\n\n @subcommand()\n async def cat(self, interaction: Interaction):\n \"\"\"Get a cat image.\"\"\"\n await interaction.response.send_message(\n embed=Embed().set_image(url=\"https://cataas.com/cat\")\n )\n\n @subcommand()\n async def dog(self, interaction: Interaction):\n \"\"\"Get a dog image.\"\"\"\n await interaction.response.send_message(\n embed=Embed().set_image(url=\"https://placedog.net/500?random\")\n )\n\n @subcommand(name=\"any\")\n async def any_(self, interaction: Interaction):\n \"\"\"Get any random image.\"\"\"\n await interaction.response.send_message(\n embed=Embed().set_image(url=\"https://picsum.photos/600\")\n )\n\n @subcommand()\n async def upload(self, interaction: Interaction, image: Attachment):\n \"\"\"Upload a new cute image.\"\"\"\n print(f\"Uploading {image.proxy_url!r}...\")\n await interaction.response.send_message(\"All done!\")\n\n\n@client.group\nclass Admin(CommandGroup):\n \"\"\"Admin-only commands.\"\"\"\n\n class Roles(CommandSubGroup):\n \"\"\"Commands to manage roles.\"\"\"\n\n @subcommand(name=\"del\")\n async def del_(self, interaction: Interaction, role: Role):\n \"\"\"Delete a role.\n\n :param role: The role to delete.\n \"\"\"\n await role.delete()\n await interaction.response.send_message(\"Deleted the role.\", ephemeral=True)\n\n\n@client.command()\nasync def ban(interaction: Interaction, user: Member):\n \"\"\"Ban a user.\n\n :param user: The user to ban.\n \"\"\"\n await user.ban()\n await interaction.response.send_message(\"Banned the user.\", ephemeral=True)\n\n\nclass RPSChoices(Choices):\n rock = \"Rock\"\n paper = \"Paper\"\n scissors = \"Scissors\"\n gun = \"Gun\"\n\n\n@client.command()\nasync def rps(interaction: Interaction, choice: RPSChoices):\n \"\"\"Play rock, paper, scissors.\n\n :param choice: Your choice.\n \"\"\"\n if choice == RPSChoices.gun:\n await interaction.response.send_message(\"That's cheating!\")\n else:\n await interaction.response.send_message(f\"You picked {choice.name}.\")\n\n\nclient.run(TOKEN)\n```\n\n## Development\n\nAs well as Python 3.9+, this project requires Poetry for development.\n[Click this link for installation instructions](https://python-poetry.org/docs/master/#installation),\nor:\n\n- #### \\*nix (Linux/MacOS)\n\n `curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -`\n\n- #### Windows Powershell\n\n `(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python -`\n\nOnce you have Poetry installed:\n\n1. **Create a virtual environment:** `poetry shell`\n2. **Install dependencies:** `poetry install`\n\nThe following commands are then available:\n\n- `poe format` - Run auto-formatting and linting.\n\nPrefix these with `poetry run` if outside of the Poetry shell.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library which supplements Nextcord by adding support for slash commands.",
"version": "0.6.4",
"project_urls": {
"Homepage": "https://github.com/artemis21/dslash",
"Repository": "https://github.com/artemis21/dslash"
},
"split_keywords": [
"discord",
"discord.py",
"nextcord",
"slash commands",
"extension"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0d4a389812ef950c2276c51c9d4437acf557c110095fe21953bb06c8c1b60555",
"md5": "bf266eee00ed84417dd6c165cdd516e1",
"sha256": "5ad5c542d7faeed26cec13811f0b2f4e0b54ccaa9431397e7d36b827894b4d81"
},
"downloads": -1,
"filename": "dslash-0.6.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bf266eee00ed84417dd6c165cdd516e1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 17740,
"upload_time": "2023-05-17T21:22:20",
"upload_time_iso_8601": "2023-05-17T21:22:20.263379Z",
"url": "https://files.pythonhosted.org/packages/0d/4a/389812ef950c2276c51c9d4437acf557c110095fe21953bb06c8c1b60555/dslash-0.6.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e41a0fd2e4d860d291f771e308928cd9654447e3b08caf095d837f4d15956ce6",
"md5": "3070298ef6940a9e818ad8af53cc7fb3",
"sha256": "2bfdbe0a89317cb522d21fd3a793e6cd824d8265ddf7f94327a08c786ae344a1"
},
"downloads": -1,
"filename": "dslash-0.6.4.tar.gz",
"has_sig": false,
"md5_digest": "3070298ef6940a9e818ad8af53cc7fb3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 16101,
"upload_time": "2023-05-17T21:22:22",
"upload_time_iso_8601": "2023-05-17T21:22:22.014915Z",
"url": "https://files.pythonhosted.org/packages/e4/1a/0fd2e4d860d291f771e308928cd9654447e3b08caf095d837f4d15956ce6/dslash-0.6.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-17 21:22:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "artemis21",
"github_project": "dslash",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "dslash"
}