A simple interaction handler for discord.py.
Project description
A simple discord slash command handler for discord.py
About ⦿ Installation ⦿ Examples ⦿ Documentation ⦿ Discord Server
About
Discord Slash Commands are a new implementation for the Bot API that utilize the forward-slash "/" symbol. Released on 15 December 2020, many bot developers are still learning to learn how to implement this into their very own bots. This command handler aims to help serve as a guidance for those looking into wanting to add these new slash commands into their bots for those that use discord.py, building off of the current library code and substituting its own for where it's needed. discord-py-slash-command stands as the first public slash command handler library to be made for Discord Bot API libraries.
Installation
You are able to easily install the discord-py-slash-command library by using the given PIP line below:
pip install -U discord-py-slash-command
Examples
Quick Startup
This is a quick startup method towards using slash commands.
import discord
from discord.ext import commands
from discord_slash import SlashCommand, SlashContext
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
slash = SlashCommand(bot)
@slash.slash(name="test")
async def _test(ctx: SlashContext):
embed = discord.Embed(title="embed test")
await ctx.send(content="test", embeds=[embed])
bot.run("discord_token")
Advanced
This offers implementation of the slash command library in the usage of a cog.
# bot.py
from discord.ext import commands
from discord_slash import SlashCommand
bot = commands.Bot(command_prefix="prefix")
slash = SlashCommand(bot, sync_commands=True, sync_on_cog_reload=True)
bot.load_extension("cog")
bot.run("TOKEN")
# cog.py
import discord
from discord.ext import commands
from discord_slash import cog_ext, SlashContext
class Slash(commands.Cog):
def __init__(self, bot):
self.bot = bot
@cog_ext.cog_slash(name="test")
async def _test(self, ctx: SlashContext):
embed = discord.Embed(title="embed test")
await ctx.send(content="test", embeds=[embed])
def setup(bot):
bot.add_cog(Slash(bot))
- This library is based on gateway event. If you are looking for webserver based, have a look at this:
- Or for other languages:
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
File details
Details for the file discord-py-slash-command-2.0.3.tar.gz
.
File metadata
- Download URL: discord-py-slash-command-2.0.3.tar.gz
- Upload date:
- Size: 35.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fc16c1ea84421dc1b593a69840abfa2e1fe8c8108b81d8cf340069c6fe23595 |
|
MD5 | 50cb219a4ca64f7e654fc67dee8413f2 |
|
BLAKE2b-256 | 31eacf256007b2fefb95a71734a1eac465f9673c7a0d37ebfc10cbd7428848af |
File details
Details for the file discord_py_slash_command-2.0.3-py3-none-any.whl
.
File metadata
- Download URL: discord_py_slash_command-2.0.3-py3-none-any.whl
- Upload date:
- Size: 39.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7ae5933dcc0c589dcc85902e0218bdec9501e0ac6106a94e61fedc51d0576bf |
|
MD5 | fbf057b3741a3973eafe24e4b4e9f11c |
|
BLAKE2b-256 | 849dabf211b46c0b1c819678f89151f63f771056de0d2f599bc82d6dda966dbb |