Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions discord/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,15 @@ def __repr__(self):


class OptionChoice:
r"""Represents an option choice.

Attributes
-----------
name: :class:`str`
The name of the option choice.
value: Optional[Union[:class:`str`, :class:`int`, :class:`float`]]
The value of the option choice. If ``None`` is passed, this will be set to the name of the option choice.
"""
def __init__(self, name: str, value: Optional[Union[str, int, float]] = None):
self.name = name
self.value = value or name
Expand Down Expand Up @@ -809,6 +818,29 @@ def to_dict(self) -> Dict[str, Union[str, int]]:


class UserCommand(ContextMenuCommand):
r"""A class that implements the protocol for user context menu commands.

These are not created manually, instead they are created via the
decorator or functional interface.

Attributes
-----------
name: :class:`str`
The name of the command.
callback: :ref:`coroutine <coroutine>`
The coroutine that is executed when the command is called.
guild_ids: Optional[List[:class:`int`]]
The ids of the guilds where this command will be registered.
cog: Optional[:class:`Cog`]
The cog that this command belongs to. ``None`` if there isn't one.
checks: List[Callable[[:class:`.ApplicationContext`], :class:`bool`]]
A list of predicates that verifies if the command could be executed
with the given :class:`.ApplicationContext` as the sole parameter. If an exception
is necessary to be thrown to signal failure, then one inherited from
:exc:`.CommandError` should be used. Note that if the checks fail then
:exc:`.CheckFailure` exception is raised to the :func:`.on_application_command_error`
event.
"""
type = 2

def __new__(cls, *args, **kwargs) -> UserCommand:
Expand Down Expand Up @@ -884,6 +916,29 @@ def _update_copy(self, kwargs: Dict[str, Any]):


class MessageCommand(ContextMenuCommand):
r"""A class that implements the protocol for message context menu commands.

These are not created manually, instead they are created via the
decorator or functional interface.

Attributes
-----------
name: :class:`str`
The name of the command.
callback: :ref:`coroutine <coroutine>`
The coroutine that is executed when the command is called.
guild_ids: Optional[List[:class:`int`]]
The ids of the guilds where this command will be registered.
cog: Optional[:class:`Cog`]
The cog that this command belongs to. ``None`` if there isn't one.
checks: List[Callable[[:class:`.ApplicationContext`], :class:`bool`]]
A list of predicates that verifies if the command could be executed
with the given :class:`.ApplicationContext` as the sole parameter. If an exception
is necessary to be thrown to signal failure, then one inherited from
:exc:`.CommandError` should be used. Note that if the checks fail then
:exc:`.CheckFailure` exception is raised to the :func:`.on_application_command_error`
event.
"""
type = 3

def __new__(cls, *args, **kwargs) -> MessageCommand:
Expand Down
44 changes: 37 additions & 7 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ AutoShardedBot
.. autoclass:: AutoShardedBot
:members:

Application Commands
---------------------
.. attributetable:: ApplicationCommandMixin

.. autoclass:: ApplicationCommandMixin
:members:

Application Info
------------------

Expand Down Expand Up @@ -1200,6 +1193,43 @@ from being stringly typed in case the strings change in the future.
All enumerations are subclasses of an internal class which mimics the behaviour
of :class:`enum.Enum`.

.. class:: SlashCommandOptionType

Specifies the input type of an option.

.. versionadded:: 2.0

.. attribute:: sub_command

A slash subcommand.
.. attribute:: sub_command_group

A slash command group.
.. attribute:: string

A string.
.. attribute:: integer

An integer.
.. attribute:: boolean

A boolean.
.. attribute:: user

A user from the current channel. This will be converted to an instance of :class:`.User` in private channels, else :class:`.Member`
.. attribute:: channel

A channel from the current guild.
.. attribute:: role

A role from the current guild.
.. attribute:: mentionable

A mentionable (user or role).
.. attribute:: number

A floating number.

.. class:: ChannelType

Specifies the type of channel.
Expand Down
94 changes: 94 additions & 0 deletions docs/application_commands.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
:orphan:

.. currentmodule:: discord
.. versionadded:: 2.0
.. _application_commands:

Application Commands
=====================

Application commands are commands that an application can register to Discord. They provide users a way of interacting
directly with your application that feels deeply integrated into Discord.

Application commands can be used with either :class:`.Bot` or :class:`.ext.commands.Bot`.

.. code-block:: python3
import discord
bot = discord.Bot()

@bot.command() # creates slash command by default
async def foo(ctx, arg):
await ctx.respond(arg)

# or

from discord.ext import commands
bot = commands.Bot()

@bot.slash_command()
async def foo(ctx, arg):
await ctx.respond(arg)

ApplicationCommand
~~~~~~~~~~~~~~~~~~~

.. attributetable:: ApplicationCommand

.. autoclass:: ApplicationCommand
:members:

SlashCommand
~~~~~~~~~~~~~

.. attributetable:: SlashCommand

.. autoclass:: SlashCommand
:members:

SlashCommandGroup
~~~~~~~~~~~~~~~~~~

.. attributetable:: SlashCommandGroup

.. autoclass:: SlashCommandGroup
:members:

Option
~~~~~~~

.. attributetable:: Option

.. autoclass:: Option
:members:

OptionChoice
~~~~~~~~~~~~~

.. attributetable:: OptionChoice

.. autoclass:: OptionChoice
:members:

UserCommand
~~~~~~~~~~~~

.. attributetable:: UserCommand

.. autoclass:: UserCommand
:members:

MessageCommand
~~~~~~~~~~~~~~~

.. attributetable:: MessageCommand

.. autoclass:: MessageCommand
:members:

ApplicationContext
~~~~~~~~~~~~~~~~~~~

.. attributetable:: ApplicationContext

.. autoclass:: ApplicationContext
:members: