Skip to main content

Support slash commands with discord.py.

Project description

Support slash commands.

Example Usage

from discord.ext import slash
client = slash.SlashBot(
    # normal arguments to commands.Bot()
    command_prefix='.', description="whatever",
    # special option: modify all global commands to be
    # actually guild commands for this guild instead,
    # for the purposes of testing. Remove this argument
    # or set it to None to make global commands be
    # properly global - note that they take 1 hour to
    # propagate. Useful because commands have to be
    # re-registered if their API definitions are changed.
    debug_guild=staging_guild_id
)

msg_opt = slash.Option(
    # description of option, shown when filling in
    description='Message to send',
    # this means that the slash command will not be invoked
    # if this argument is not specified
    required=True)

@client.slash_cmd() # global slash command
async def repeat( # command name
    ctx: slash.Context, # there MUST be one argument annotated with Context
    message: msg_opt
):
    """Make the bot repeat what you say""" # description of command
    # respond to the interaction, must be done within 3 seconds
    await ctx.respond(message, # string (or str()able) message
        # sends a response message immediately
        rtype=slash.InteractionResponseType.ChannelMessageWithSource)

client.run(token)

Notes

  • slash.Context emulates commands.Context, but only to a certain extent. Notably, ctx.message does not exist, because slash commands can be run completely without the involvement of messages. However, channel and author information is still available.

  • All descriptions are required.

  • You must grant the bot applications.commands permissions in the OAuth2 section of the developer dashboard.

See the wiki.

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-ext-slash-0.5.0rc1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

discord_ext_slash-0.5.0rc1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file discord-ext-slash-0.5.0rc1.tar.gz.

File metadata

  • Download URL: discord-ext-slash-0.5.0rc1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.0

File hashes

Hashes for discord-ext-slash-0.5.0rc1.tar.gz
Algorithm Hash digest
SHA256 2ba06f873a00126bf4dff133cf56317c2d9ea7b0a455eae31b37dea6154149d7
MD5 a35f52ad6953d7f0dc28ca2cb83b324d
BLAKE2b-256 2c561dc6f5820685c9e67468eb35237383f80e9933076890f0cb73d0a251524f

See more details on using hashes here.

Provenance

File details

Details for the file discord_ext_slash-0.5.0rc1-py3-none-any.whl.

File metadata

  • Download URL: discord_ext_slash-0.5.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.0

File hashes

Hashes for discord_ext_slash-0.5.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 dece40a84284c5457b4a883229164920a513b4833b9f4958e3341d5d5e2ebfba
MD5 2bfdc591b300886dda19a5ebaec24ae1
BLAKE2b-256 66145be3bbd2f321fb0b8eb3c4bcc3d0ba98fd01c37d710c5aba0f13cb5b182a

See more details on using hashes here.

Provenance

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