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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions docs/Extensions/Commands.mdx

This file was deleted.

158 changes: 158 additions & 0 deletions docs/Extensions/Commands/creating-prefixed-commands.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
title: Creating Prefixed Commands
description: Learn how to use the commands extention for Pycord.
---

import {
DiscordButton,
DiscordButtons,
DiscordInteraction,
DiscordMessage,
DiscordMessages,
} from "@discord-message-components/react";
import "@discord-message-components/react/styles";

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

Before Discord added slash commands, all bots had prefixed commands. A user would type `!ping` or `?ping` or whatever the bot's prefix was to get a response.
However, this prefixed commands system isn't native to Discord! Developers made use of the `on_message` event to check if the message began with a `!ping`. So every time a message was sent, the bot would check if it began with the prefix, or with the command name.

The syntax becomes a little more complicated when you want to have multiple commands. There are several more disadvances to this system. This is where the commands extention comes in.
`ext.commands` has various advantages, such as:

- Simpler syntax
- Easier to use
- Easier to parse user input
- Comes with build-in help commands
- Comes with a built-in system for categorizing commands

<Tabs>
<TabItem value="0" label="Using Events to Create Prefixed Commands" default>

```python
import discord

client = discord.Client()

@client.event
async def on_message(message):
if message.content.startswith("!ping"):
await message.channel.send("Pong!")

elif message.content.startswith("!announce"):
if len(message.content.split(" ")) < 3:
await message.channel.send("You need to specify a title and a message. Correct usage: `!announce Hello Hello everyone!`")
return

msg = message.content.split(" ", 2)
title = msg[1]
content = msg[2]

await message.channel.send("**{}**\n{}".format(title, content))

elif message.content.startswith("!"):
await message.channel.send("Unknown command.")
```

<DiscordMessages>
<DiscordMessage author="Guide User" avatar="blue">
!ping
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
Pong!
</DiscordMessage>
<DiscordMessage author="Guide User" avatar="blue">
!announce Hello Hello World!
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
<strong>Hello</strong>
<br />
Hello World!
</DiscordMessage>
<DiscordMessage author="Guide User" avatar="blue">
!help
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
Unknown Command.
</DiscordMessage>
</DiscordMessages>

</TabItem>
<TabItem value="1" label="Using the Commands Extension">

```python
import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="!")

@bot.command()
async def ping(ctx):
await ctx.send("Pong!")

@bot.command()
async def announce(ctx, title, *, message):
await ctx.send("**{}**\n{}".format(title, message))

@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("Unknown command.")
```

<DiscordMessages>
<DiscordMessage author="Guide User" avatar="blue">
!ping
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
Pong!
</DiscordMessage>
<DiscordMessage author="Guide User" avatar="blue">
!announce Hello Hello World!
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
<strong>Hello</strong>
<br />
Hello World!
</DiscordMessage>
<DiscordMessage author="Guide User" avatar="blue">
!pycord
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
Unknown command.
</DiscordMessage>
<DiscordMessage author="Guide User" avatar="blue">
!help
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
<code>
No Category:
<br />
<div style={{ paddingLeft: "2em" }}>
!help Shows this message
<br />
!ping
<br />
!announce
</div>
<br />
Type !help command for more info on a command.
<br />
You can also type !help category for more info on a category.
</code>
</DiscordMessage>
</DiscordMessages>

<br/>

:::tip

You can do much more with the commands extention! This example only showcases the same features as the previous example. You can use a different built-in help command, or even create your own! You will learn about creating Help Commands and Categories in the next tutorials.

:::

</TabItem>
</Tabs>

## Getting Started
81 changes: 81 additions & 0 deletions docs/Extensions/Commands/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: Commands
description: Learn how to use the commands extention for Pycord.
---

import {
DiscordButton,
DiscordButtons,
DiscordInteraction,
DiscordMessage,
DiscordMessages,
} from "@discord-message-components/react";
import "@discord-message-components/react/styles";

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

Before Discord added slash commands, all bots had prefixed commands. A user would type `!ping` or `?ping` or whatever the bot's prefix was to get a response.
However, this prefixed commands system isn't native to Discord! Developers made use of the `on_message` event to check if the message began with a `!ping`. So every time a message was sent, the bot would check if it began with the prefix, or with the command name.

The syntax becomes a little more complicated when you want to have multiple commands. There are several more disadvances to this system. This is where the commands extention comes in.
`ext.commands` has various advantages, such as:

- Simpler syntax
- Easier to use
- Easier to parse user input
- Comes with build-in help commands
- Comes with a built-in system for categorizing commands

<Tabs>
<TabItem value="0" label="Using Events to Create Prefixed Commands" default>

```python
import discord

client = discord.Client()

@client.event
async def on_message(message):
if message.content.startswith("!ping"):
await message.channel.send("Pong!")
```

<DiscordMessages>
<DiscordMessage author="Guide User" avatar="blue">
!ping
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
Pong!
</DiscordMessage>
</DiscordMessages>

</TabItem>
<TabItem value="1" label="Using the Commands Extension">

```python
import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="!") # You can change the prefix to whatever you want

@bot.command()
async def ping(ctx):
await ctx.send("Pong!")
```

<DiscordMessages>
<DiscordMessage author="Guide User" avatar="blue">
!ping
</DiscordMessage>
<DiscordMessage author="Guide Bot" avatar="red" bot>
Pong!
</DiscordMessage>
</DiscordMessages>

</TabItem>
</Tabs>

## Getting Started


7 changes: 0 additions & 7 deletions docs/Extensions/index.mdx

This file was deleted.

44 changes: 31 additions & 13 deletions docs/Interactions/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,46 @@ import {
} from "@discord-message-components/react";
import "@discord-message-components/react/styles";

# Discord Interactions
Back in the December 2020, Discord released their first interaction: the slash command.
Since then, Discord has added and updated Interactions a lot. Different types of Interactions are:

Back in the December of 2020, Discord released their first interaction: the slash command. This was
the beginning to a great deal of amazing Message Components and Application Commands in Discord.
Since then, Discord also added:
__**Message Components**__

- Buttons
- Select Menus
- Text Modals
- Message commands
- User Commands
- **Buttons**: buttons that can be clicked on to perform an action
- **Select Menus**: Dropdowns used to select an option from a list of options
- **Modals**: Form-like modals that can be used to ask for input

__**Application Commands**__

- **Slash Commands**: Commands that can be used to perform an action
- **Context Menu Commands**
- **User Commands:** Commands that can be used *on* a user by right clicking/selecting them
- **Message Commands:** Commands that can be used on a message by right clicking/selecting it

Buttons, Select Menus, and Text Modals fall under the `Message Components` category, while Slash
Commands, Message Commands, and User Commands fall under the `Application Commands` category. Keep
reading to find out more about Message Components and Application Commands and why they're useful for
your application, as well as the pros and cons of using them.

## Message Components

Message Components are fairly new features in Discord, allowing developers to give their bots a fast
and understandable user interface. Message Components are easy to use and make your bot look modern,
sleek, and downright awesome.

### Views

Views are not an Application Command nor are they a Message Component. Views are the invisible
placeholders or grid that Message Components lie in. Views can have up to 5 `Action Rows`. `Action
Rows` can have a maximum of 5 slots. Below you can find a table of how many slots a Message
Interaction takes up.

| Component | Slots |
| ------------------------------------------- |
| Buttons | 1 Slot |
| Select Menus | 5 Slots |
| Text Modals | 1 Slot (opened via a button) |

So, based on this, you could have a maximum of 25 buttons in a View with no Select Menus and 5 Select
Menus with no Buttons in a View. This doesn't mean you can't have them both in a View. You can have
a combination, such as 20 Buttons and a Select Menu or 10 Buttons and 3 Select Menus.

### Buttons

Buttons are the first of the Message Components. They allow for quick responses to prompts, such as
Expand Down Expand Up @@ -81,6 +98,7 @@ are opened by clicking on a button.

This is what a Text Modal looks like. Easy to use and one of the most useful Message Components yet.


### Views

Views are not an Application Command nor are they a Message Component. Views are the invisible
Expand Down
10 changes: 9 additions & 1 deletion sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ const sidebars = {
{
type: "category",
label: "Extensions",
items: ["Extensions/Commands", "Extensions/Pages"],
items: [
{
type: "category",
label: "Commands",
items: [
"Extensions/Commands/creating-prefixed-commands",
]
}
],
},
{
type: "category",
Expand Down