Pyslash
Pyslash is a wrapper around discord-py-slash-command, that makes command creation more natural.
The examples provided are based of the examples from the original repository.
Quick startup
Firstly you must install the package, as explained here.
A simple setup using slash and adding a basic command.
import discord
from discord.ext import commands
from pyslash import SlashCommand, SlashContext
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
s = SlashCommand(bot)
@s.slash(name="test")
async def _test(ctx: SlashContext, arg0: str):
embed = discord.Embed(title="embed test")
await ctx.send(content=arg0, embeds=[embed])
bot.run("discord_token")
As of 1.1.0, you no longer need to import slash from pyslash and provide the instance as the first variable, as pyslash now has a subclass of SlashCommand that does this for you.
Converters are automatically handled, for example
@s.slash(name="test")
async def _test(ctx: SlashContext, member: discord.Member):
await ctx.send(f"*taps mic* testing, {member.mention}")
And names don't have to be given
@s.slash()
async def foo(ctx: SlashContext, member: discord.Member):
# This command will automatically be called 'foo'
await ctx.send(f"Hello, {member.mention}")
Descriptions
By default, each argument and command has the description No description, but that can be changed by providing a docstring. Docstrings are supported as provided by docstring-parser — at time of writing, that is ReST, Google, and Numpydoc.
from typing import Tuple, Literal
# ...
@s.slash()
async def foo(ctx: SlashContext, member: discord.Member):
"""
My command description here!
:param member: my description here
"""
# This command will automatically be called 'foo', and have the description
# "My command description here!", and the argument `member` will have the
# description "my description here".
await ctx.send(f"Hello, {member.mention}")
It's also possible to pass the command description through the decorator as follows, although that's not recommended (and will override any docstring provided description):
@s.slash(description="My description!")
async def command(ctx):
pass
Advanced usage
The same usage applies for cogs, but a different function is used.
# bot.py
from discord.ext import commands
from pyslash import SlashCommand
bot = commands.Bot(command_prefix="prefix")
slash = SlashCommand(bot, override_type = True)
bot.load_extension("cog")
bot.run("TOKEN")
# cog.py
import discord
from discord.ext import commands
from pyslash import SlashContext, slash_cog
class Slash(commands.Cog):
def __init__(self, bot):
self.bot = bot
@slash_cog(name="test")
async def _test(self, ctx: SlashContext):
await ctx.send("Hey there folks")
def setup(bot):
bot.add_cog(Slash(bot))
Installation
To install from pip, run
pip install dpyslash
To install from source, clone the repository and then build:
git clone https://github.com/starsflower/discordpy-slash-commands.git
cd discordpy-slash-commands
python setup.py install
Tests
To run basic tests, run
python -m tests/test
To run the test bot (that requires BOT_TOKEN in the environment variables), and a further pip requirement of python-dotenv
python -m tests/test_bot
Metadata
Release files for dpyslash 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dpyslash-1.2.2.tar.gz | 7.7 kB | Without provenance | Details for dpyslash-1.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dpyslash-1.2.2-py3-none-any.whl | Python 3 | none | any | Details for dpyslash-1.2.2-py3-none-any.whl |
Total release size: 17.2 kB
Release files / dpyslash-1.2.2.tar.gz
| Download URL | dpyslash-1.2.2.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
08a4202d92ae27592f9c4c8bcd963a96606a2eaa329d54f65092f3f6de4da00b
|
|
BLAKE2b-256 checksum How to use checksums |
ca74f47b655a5c727a828380c94faebf9be5fe98c725ffedb74b397dbaac4d63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / dpyslash-1.2.2-py3-none-any.whl
| Download URL | dpyslash-1.2.2-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6d63d5ed97f7f74fdfb8876366c5c1446d6fd047bce7d1c567361b8d7cc6e99
|
|
BLAKE2b-256 checksum How to use checksums |
5814e8c197394434f32f938c1109aeff055f17e97e088a1e45e26d067b9e8e1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for dpyslash 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.