Skip to main content

A simple discord slash command handler for discord.py.

Project description


discord-py-slash-command

A simple discord slash command handler for discord.py

Codacy Badge Discord

About ⦿ Installation ⦿ Disclaimer ⦿ Examples ⦿ Documentation ⦿ Discussions ⦿ 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

Disclaimer

Since slash commands are currently not officially released (They're in public beta), there will be many breaking changes to this extension which may cause it to become unstable. It is recommended to wait until discord officially releases slash commands. Waiting until Release 1.1.0, which is planned to have most features implemented in the code, is also recommended. At this time, the developer of discord.py has no plans to officially support slash commands for their library.

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, override_type = 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:
dispike
discord-interactions-python
Or for other languages:
discord-api-docs Community Resources: Interactions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord-py-slash-command-1.0.9.4.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

discord_py_slash_command-1.0.9.4-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file discord-py-slash-command-1.0.9.4.tar.gz.

File metadata

  • Download URL: discord-py-slash-command-1.0.9.4.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for discord-py-slash-command-1.0.9.4.tar.gz
Algorithm Hash digest
SHA256 954e3d2fde44eae43e5d592cf2aaf2cd484ac0d3490a4d5f2e72d3d3b5138145
MD5 af537cf41b9462071958f7ba1c156b65
BLAKE2b-256 1d279a7e6e3cb269881caf140836fb4e82eb116aedd82112b48c906b32c9c7f7

See more details on using hashes here.

File details

Details for the file discord_py_slash_command-1.0.9.4-py3-none-any.whl.

File metadata

  • Download URL: discord_py_slash_command-1.0.9.4-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for discord_py_slash_command-1.0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c4fc7eeb68e051344df88c309207bca2437ab556226937763bc57fc48352c70c
MD5 9f1997c07aed00be914ba17f83ed95ca
BLAKE2b-256 a1ccb579937a0c4c68fa52d12846eccd9c3998f94637e2f2e8fd764339ea18a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page