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
):
    """Send a message in the bot's name""" # description of command
    # respond to the interaction, must be done within 3 seconds
    await ctx.respond(message, # string (or str()able) message
        # sends a message without showing the command invocation
        rtype=slash.InteractionResponseType.ChannelMessage)

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.

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.2.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

discord_ext_slash-0.2.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file discord-ext-slash-0.2.1.tar.gz.

File metadata

  • Download URL: discord-ext-slash-0.2.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 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.2.1.tar.gz
Algorithm Hash digest
SHA256 5543f3a17660a2aa52d91f511ba38e2d415ff6a8925b76d1abc4d41fdfe7b767
MD5 dd4ffb091e9946b3671ffadd5d0a0ed9
BLAKE2b-256 b088792d4060d377a41ac9834beb500b1919c88bfd5266fcc0944d6fb69e6573

See more details on using hashes here.

Provenance

File details

Details for the file discord_ext_slash-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: discord_ext_slash-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 522191bde47ecf1d6b6f5bd8a9ca7f950c6b392b20e8227a711d86aeee40a0bd
MD5 e6b3d23ee624408c1489699cbce77f06
BLAKE2b-256 477f4a721be262ec4fbd1f647eaae07c3a6e43f00470c82924ffcf33e29c929f

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