|
| 1 | + |
| 2 | +Support slash commands. |
| 3 | + |
| 4 | +Example Usage |
| 5 | +============= |
| 6 | + |
| 7 | +.. code-block:: python |
| 8 | +
|
| 9 | + from discord.ext import slash |
| 10 | + client = slash.SlashBot( |
| 11 | + # normal arguments to commands.Bot() |
| 12 | + command_prefix='.', description="whatever", |
| 13 | + # special option: modify all global commands to be |
| 14 | + # actually guild commands for this guild instead, |
| 15 | + # for the purposes of testing. Remove this argument |
| 16 | + # or set it to None to make global commands be |
| 17 | + # properly global - note that they take 1 hour to |
| 18 | + # propagate. Useful because commands are |
| 19 | + # re-registered every time the bot starts. |
| 20 | + debug_guild=7293012031203012 |
| 21 | + ) |
| 22 | +
|
| 23 | + msg_opt = slash.Option( |
| 24 | + # description of option, shown when filling in |
| 25 | + description='Message to send', |
| 26 | + # this means that the slash command will not be invoked |
| 27 | + # if this argument is not specified |
| 28 | + required=True) |
| 29 | +
|
| 30 | + @client.slash_cmd() # global slash command |
| 31 | + async def repeat( # command name |
| 32 | + ctx: slash.Context, # there MUST be one argument annotated with Context |
| 33 | + message: msg_opt |
| 34 | + ): |
| 35 | + """Send a message in the bot's name""" # description of command |
| 36 | + await ctx.respond(message, # respond to the interaction |
| 37 | + # sends a message without showing the command invocation |
| 38 | + rtype=slash.InteractionResponseType.ChannelMessage) |
| 39 | +
|
| 40 | + client.run(token) |
| 41 | +
|
| 42 | +Notes |
| 43 | +===== |
| 44 | +* ``slash.Context`` emulates ``commands.Context``, but only to a certain extent. |
| 45 | + Notably, ``ctx.message`` does not exist, because slash commands can be run |
| 46 | + completely without the involvement of messages. However, channel and author |
| 47 | + information is still available. |
| 48 | +* All descriptions are **required**. |
| 49 | + |
| 50 | +Not Yet Supported |
| 51 | +================= |
| 52 | +* Subcommands |
0 commit comments