Force the discord.py command framework to correspond to the slashes.
Project description
discord-ext-fslash
This library registers commands from discord.py command framework as slash commands in discord.py as well by doing a monkey patch.
WARNING
Again, the way this library works is a monkey patch and is not without the possibility of unexpected behavior.
Features
It supports both the cooldown and other decorators of the command framework and the describe decorator of the app command to work.
The converter will automatically replace to the Transformer of slash version.
It can also automatically convert invalid annotations to str and register overnested group commands by accepting subcommands from command arguments.
Even if you have too many commands and reach the maximum number of can be registered slash commands, we have a way to deal with it. (An example is below)
If you are planning to create a bot, we recommend using HybridCommand, which comes standard in discord.py.
Installation
$ pip install discord-ext-fslash
Example
Normal
The following is an example of creating a command called ping that works with both slash and message commands.
from discord.ext.fslash import extend_force_slash
...
bot = extend_force_slash(commands.Bot(command_prefix="fs!", intents=intents))
@bot.command()
async def ping(ctx):
await ctx.reply("pong")
Split Commands by Categories
Even if there are too many commands in the command framework to register in the slash, it provides a way to implement them all by making only the commands in the slash subcommands of the group command.
The following example creates the group commands server-tool and entertainment and sets up the commands in the command framework as subcommands of those commands.
from discord.ext.fslash import extend_force_slash
...
bot = extend_force_slash(
commands.Bot(command_prefix="fs!", intents=intents),
first_groups=(
discord.app_commands.Group(name="server-tool"),
discord.app_commands.Group(name="entertainment")
)
)
@bot.command(description="Ban member", fsparent="server-tool")
@commands.has_guild_permissions(ban_members=True)
@commands.bot_has_guild_permissions(ban_members=True)
@commands.cooldown(1, 10, commands.BucketType.guild)
@discord.app_commands.describe(member="Member to be banned")
async def ban(ctx, *, member: discord.Member):
# `/server-tool ban member: ...` or `fs!ban ...` to run this command.
await ctx.typing()
await member.ban()
await ctx.reply("pong")
@bot.command(description="Make wow", fsparent="entertainment")
async def wow(ctx):
# `/entertainment wow` or `fs!wow` to run this command.
await ctx.reply("wow")
Documentation
There are features to improve compatibility for greater convenience.
See the documentation for details.
Contributing
Issues and PullRequests should be brief in content.
The code should be similar in style to the current code.
Please limit all text to 100 characters per line if possible, except for comments.
For comments, please limit to 200 characters per line if possible.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file discord-ext-fslash-0.2.1.tar.gz.
File metadata
- Download URL: discord-ext-fslash-0.2.1.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1df7af553f3bc68f06f51280c13ac4e0c577387ad2376d6acb24e8e0043b7c6a
|
|
| MD5 |
37b4da140165b434176aafc3d82c8258
|
|
| BLAKE2b-256 |
c7058a489f0ac4664bdaf93a49dd3cd18ade15d2775bb06da3c8bb126a4fdd5d
|
File details
Details for the file discord_ext_fslash-0.2.1-py3-none-any.whl.
File metadata
- Download URL: discord_ext_fslash-0.2.1-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
220cca724e708ab6f470d1313c745a8073a739ac599c0d94a02cb6736930c0bf
|
|
| MD5 |
3c649856eb247d3cd738fc4712b99486
|
|
| BLAKE2b-256 |
4ebe4947769d5777c7f2a5678c4a5966b7a9342d235b3b7fbb246ec7becd1d95
|