Skip to content

Commit

Permalink
Add slash command example to quickstart (Pycord-Development#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
hypergonial authored Dec 29, 2021
1 parent 8e5ef7e commit 0711ee7
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
.. currentmodule:: discord

Quickstart
============
==========

This page gives a brief introduction to the library. It assumes you have the library installed,
if you don't check the :ref:`installing` portion.

A Minimal Bot
---------------
-------------

Let's make a bot that responds to a specific message and walk you through it.

Expand Down Expand Up @@ -40,7 +40,7 @@ It looks something like this:
Let's name this file ``example_bot.py``. Make sure not to name it ``discord.py`` as that'll conflict
with the library.

There's a lot going on here, so let's walk you through it step by step.
There's a lot going on here, so let's walk you through it step by step:

1. The first line just imports the library, if this raises a `ModuleNotFoundError` or `ImportError`
then head on over to :ref:`installing` section to properly install.
Expand Down Expand Up @@ -77,3 +77,41 @@ On other systems:
$ python3 example_bot.py
Now you can try playing around with your basic bot.

A Minimal Bot with Slash Commands
---------------------------------

As a continuation, let's create a bot that registers a simple slash command!

It looks something like this:

.. code-block:: python3
import discord
bot = discord.Bot()
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
@bot.slash_command(guild_ids=[your, guild_ids, here])
async def hello(ctx):
await ctx.respond("Hello!")
bot.run("your token here")
Let's look at the differences compared to the previous example, step-by-step:

1. The first line remains unchanged.
2. Next, we create an instance of :class:`.Bot`. This is different from :class:`.Client`, as it supports
slash command creation and other features, while inheriting all the features of :class:`.Client`.
3. We then use the :meth:`.Bot.slash_command` decorator to register a new slash command.
The ``guild_ids`` attribute contains a list of guilds where this command will be active.
If you omit it, the command will be globally available, and may take up to an hour to register.
4. Afterwards, we trigger a response to the slash command in the form of a text reply. Please note that
all slash commands must have some form of response, otherwise they will fail.
6. Finally, we, once again, run the bot with our login token.


Congratulations! Now you have created your first slash command!

0 comments on commit 0711ee7

Please sign in to comment.