# Slash Commands

{% hint style="danger" %}
This guide has been moved to <https://namantech.me/pycord>. Please visit the new guide instead, since this one might be outdated.

The new guide looks better, has better explanations, and is way better overall.
{% endhint %}

Docs: <https://pycord.readthedocs.io/en/master/api.html#discord.Bot.slash_command>

## Simple Slash Command

Simple Example:

```python
import discord
from discord.app import Option

bot = discord.Bot()

# Note: If you want you can use commands.Bot instead of discord.Bot
# Use discord.Bot if you don't want prefixed message commands

# With discord.Bot you can use @bot.command as an alias 
# of @bot.slash_command but this is overriden by commands.Bot


@bot.slash_command(guild_ids=[...])  # create a slash command for the supplied guilds
async def hello(ctx):
    """Say hello to the bot"""  # the command description can be supplied as the docstring
    await ctx.send(f"Hello {ctx.author}!")


@bot.slash_command(
    name="hi", description="Wish someone!"
)  # Not passing in guild_ids creates a global slash command (might take an hour to register)
async def global_command(ctx, num: int):  # Takes one integer parameter
    await ctx.send(f"This is a global command, {num}!")


@bot.slash_command(guild_ids=[...])
async def joined(
    ctx, member: discord.Member = None
):  # Passing a default value makes the argument optional
    user = member or ctx.author
    await ctx.send(f"{user.name} joined at {discord.utils.format_dt(user.joined_at)}")
    
    
choose = bot.command_group(
    name='choose', description='This is a slash command group!', guild_ids=[...])

@choose.command(name='member')
async def choose_a_user(ctx,
    user: Option(discord.Member, "Choose a member", required=False), #required is True by default
):
    await ctx.send(f"You chose {user}!")

@choose.command()
async def choose_a_channel(ctx,
    channel: Option(discord.Channel, "Choose a channel"),
):
    await ctx.send(f"You chose {channel}!")

bot.run("TOKEN")
```

{% hint style="info" %}
You need to have Py-cord version 2.0 Alpha to use Slash Commands
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://brucecodes.gitbook.io/pycord/interactions/slash-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
