Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Commands Documentation #309

Merged
merged 31 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d8685d3
Application Commands Documentation
VincentRPS Dec 26, 2021
45f8839
examples: better docs thingy for autocomplete example
VincentRPS Dec 26, 2021
8ec763e
Fix some stuff
VincentRPS Dec 26, 2021
193394a
i've spent too long at my computer for today
VincentRPS Dec 26, 2021
ea8df32
some changes ooliver wanted in the old pull
VincentRPS Dec 26, 2021
103b369
Show Client decorated decorators
VincentRPS Dec 26, 2021
2677ffc
review comments from ooliver
VincentRPS Dec 27, 2021
3c957fa
making prefix more consistant
VincentRPS Dec 27, 2021
d7c8d91
oops
VincentRPS Dec 27, 2021
a9b81ac
typo
VincentRPS Dec 27, 2021
3adbaa3
black changes
VincentRPS Dec 27, 2021
34d57cb
Fixing Some Stuff ooliver wanted
VincentRPS Dec 27, 2021
f418377
Apply suggestions from code review
VincentRPS Dec 27, 2021
1296afd
should fix everything epic wanted
VincentRPS Dec 27, 2021
f4b76c8
Merge branch 'docs' of https://github.com/VincentRPS/nextcord into docs
VincentRPS Dec 27, 2021
64b4dd9
use Client
VincentRPS Dec 27, 2021
3890e17
E
VincentRPS Dec 27, 2021
8b9a61b
Some small fixes
VincentRPS Dec 28, 2021
cbfbc5d
Fix up options example
VincentRPS Dec 31, 2021
8a87438
Update options.py
VincentRPS Dec 31, 2021
6530b9a
chore: apply suggestions from code review
vcokltfre Jan 12, 2022
4a221b2
chore: remove unneeded line
vcokltfre Jan 15, 2022
16d8ec0
Merge branch 'nextcord:master' into docs
VincentRPS Jan 18, 2022
f2eedc2
chore: fix some stuff
VincentRPS Jan 21, 2022
cfbe9b4
chore: apply code review changes
vcokltfre Jan 21, 2022
f90cd50
chore: clean up app commands examples
vcokltfre Jan 21, 2022
98a0724
chore: fix interactions doc formatting
vcokltfre Jan 21, 2022
8b6808a
Merge branch 'nextcord:master' into docs
VincentRPS Jan 22, 2022
0706247
chore: apply suggestions
VincentRPS Jan 22, 2022
ef37c2c
chore: apply suggestions
VincentRPS Jan 22, 2022
3ccfeb7
chore: apply suggestions
VincentRPS Jan 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 50 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@ Client

.. autoclass:: Client
:members:
:exclude-members: fetch_guilds, event
:exclude-members: fetch_guilds, event, slash_command, user_command, message_command

.. automethod:: Client.event()
:decorator:

.. automethod:: Client.slash_command
:decorator:

.. automethod:: Client.user_command
:decorator:

.. automethod:: Client.message_command
:decorator:

.. automethod:: Client.fetch_guilds
:async-for:

Expand Down Expand Up @@ -4178,6 +4187,46 @@ Select
.. autofunction:: nextcord.ui.select


Application Commands
--------------------

.. attributetable:: ApplicationCommand

.. autoclass:: ApplicationCommand
:members:

.. attributetable:: ApplicationSubcommand

.. autoclass:: ApplicationSubcommand
:members:

Options
~~~~~~~

.. attributetable:: CommandOption

.. autoclass:: CommandOption
:members:

.. attributetable:: SlashOption

.. autoclass:: SlashOption
:members:

Cogs
~~~~

.. autoclass:: ClientCog
:members:
Decorators
~~~~~~~~~~

.. autoclass:: message_command

.. autoclass:: slash_command

.. autoclass:: user_command

Exceptions
------------

Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ If you're looking for something related to the project itself, it's here.

whats_new
version_guarantees
interactions
migrating
migrating_2
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
migrating_to_nextcord
migrating_to_slash_commands
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
131 changes: 131 additions & 0 deletions docs/interactions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
:orphan:

.. currentmodule:: nextcord

.. _interactions:

Slash Commands
==============

Since Discord has added interaction commands a feature with many possibilities, we at Nextcord have decided to add them to our fleet of features.
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

This doc will explain the innerworkings and how to use interaction commmands.
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

We suggest you learn how to make regular commands before looking through here, we suggest looking at the :doc:`quickstart`
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

How To Make A Simple Slash Command
----------------------------------

This right here is a simple ping pong command made with Nextcords slash feature.
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python3

@bot.slash_command(name="ping")
async def ping(interaction):
await interaction.response.send_message("Pong!")

The way it works is that you use the :meth:`~Client.slash_command` function to interact with the Discord API. The ``name`` parameter is the name of your slash command.
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved

``guild_ids`` is used to limit the guilds that the slash command is available to. This is also useful for testing, as global slash commands can take up to an hour to register.
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

Example:

.. code-block:: python3

@bot.slash_command(guild_ids=[id1, id2])
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved

How To Use Sub-Commands
-----------------------

The way sub-commands work is that you make a normal slash command that will never be called, and then make the sub-commands and have them do the work of real slash commands. There is no difference with slash commands and sub-commands. The only thing you will need to change is functions.
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

As shown in the demonstration below you make a main slash command or a dummy slash command and build sub-commands off it.

.. code-block:: python3

@bot.slash_command(guild_ids=[...]) # Making the command and limiting the guilds
async def main(interaction):
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
# passing through interaction and indentifing the sub-command group name
await interaction.response.send_message(
"This will never get called if this has subcommands."
) # a function never called
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved


@main.subcommand() # Identifying The Sub-Command
async def sub1(interaction): # Making The Sub Command Name And Passing Through Interaction
await interaction.response.send_message(
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
"This is subcommand 1!"
) # Sending A Response
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved


@main.subcommand(description="Aha! Another subcommand")
# Identifying The Sub-Command And Adding A Descripton
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
async def subcommand_two(interaction: Interaction): # Passing in interaction

await interaction.response.send_message(
"This is subcommand 2!"
) # Responding With The Args/Fields
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

Fields And Requirements
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
-----------------------
Fields are meant to facilitate an easier way to fill info, letting people using your slash command get a different response for each answer.

Nextcord's implementation of slash commands has fields and is very simple. in the example below is a field.

.. code-block:: python3

@bot.slash_command(name="help")
async def help(
interaction: Interaction,
setting: str = SlashOption(name="settings", description="Configure Your Settings")
):
if setting == "music":
await interaction.response.send_message(f"Sorry we aren't connected to lavalink currently")
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
elif setting == "moderation":
await interaction.response.send_message(f"Moderation?")
else:
await interaction.response.send_message("Odd, I don't know that setting")
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved


How To Make Slash Commands In Cogs
----------------------------------
Show below is an example of a simple command running in a cog.
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python3

class ExampleCog(commands.Cog):
def __init__(self):
self.count = 0

@slash_command(name="cogexample")
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
async def slash_example_cog_command(self, interaction):
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved
await interaction.response.send_message("Hello i am a slash command in a cog!")
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

The example shown above responds to a user when they do a slash command. It is identical to a normal slash command and to normal commands in general.
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

How To Make Context Menu Commands
---------------------------------
Context Menu commands display commands on a menu of a message/user.
vcokltfre marked this conversation as resolved.
Show resolved Hide resolved

User Commands
~~~~~~~~~~~~~~
What you see below is a example of a simple user command.
It is a user dump command that dumps user data.
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python3

@bot.user_command(name="dump")
async def userdump(interaction, member):
await interaction.response.send_message(f"Member: {member}, Data Dump: {interaction.data}")

Message Commands
~~~~~~~~~~~~~~~~~
What you see below is a example of a simple message command,
VincentRPS marked this conversation as resolved.
Show resolved Hide resolved
It's a message dump command that dumps message data.

.. code-block:: python3

@bot.message_command(name="dump")
async def messagedump(interaction, message: Message):
await interaction.response.send_message(f"Data Dump: {interaction.data}")