|
1 | | ---- |
2 | | -title: Command Groups |
3 | | ---- |
4 | | - |
5 | | -Command groups are a way to create subcommands for your commands. For example, `!afk set` or `!afk |
6 | | -remove`. |
7 | | - |
8 | | -## Syntax |
9 | | - |
10 | | -Creating a command group is very simple. |
11 | | - |
12 | | -```python title="Command Groups Example" |
13 | | -import discord |
14 | | -from discord.ext import commands |
15 | | - |
16 | | -bot = commands.Bot(command_prefix='!') |
17 | | - |
18 | | -@bot.group() |
19 | | -async def afk(): |
20 | | - pass |
21 | | - |
22 | | -@afk.command() |
23 | | -async def set(): |
24 | | - ... |
25 | | - |
26 | | -@afk.command() |
27 | | -async def remove(): |
28 | | - ... |
29 | | - |
30 | | -# Another command group |
31 | | - |
32 | | -@bot.group(invoke_without_command=True) # Indicates if the group callback should begin parsing and invocation only if no subcommand was found. |
33 | | -async def math(ctx): |
34 | | - await ctx.send('Subcommand not found') |
35 | | - |
36 | | -@math.command() |
37 | | -async def add(ctx, a: int, b: int): |
38 | | - ... |
39 | | - |
40 | | -@math.command() |
41 | | -async def subtract(ctx, a: int, b: int): |
42 | | - ... |
43 | | -``` |
44 | | - |
45 | | -To create a command group, the command's decorator must be `@bot.group`. Once you have a command with |
46 | | -that decorator, you can use `@function.command()`, such as `@math.command()`. Now, you have subcommand |
47 | | -groups! |
48 | | - |
49 | | -<!-- Waiting for slash command groups in Pycord --> |
50 | | - |
51 | | -:::info Related Topics |
52 | | - |
53 | | -- [Prefixed Commands](./prefixed-commands.mdx) |
54 | | -- [Cogs](../../popular-topics/cogs) |
55 | | - |
56 | | -::: |
| 1 | +--- |
| 2 | +title: Command Groups |
| 3 | +--- |
| 4 | + |
| 5 | +Command groups are a way to create subcommands for your commands. For example, `!afk set` or `!afk |
| 6 | +remove`. |
| 7 | + |
| 8 | +## Syntax |
| 9 | + |
| 10 | +Creating a command group is very simple. |
| 11 | + |
| 12 | +```python title="Command Groups Example" |
| 13 | +import discord |
| 14 | +from discord.ext import commands |
| 15 | + |
| 16 | +bot = commands.Bot(command_prefix='!') |
| 17 | + |
| 18 | +@bot.group() |
| 19 | +async def afk(): |
| 20 | + pass |
| 21 | + |
| 22 | +@afk.command() |
| 23 | +async def set(): |
| 24 | + ... |
| 25 | + |
| 26 | +@afk.command() |
| 27 | +async def remove(): |
| 28 | + ... |
| 29 | + |
| 30 | +# Another command group |
| 31 | + |
| 32 | +@bot.group(invoke_without_command=True) # Indicates if the group callback should begin parsing and invocation only if no subcommand was found. |
| 33 | +async def math(ctx): |
| 34 | + await ctx.send('Subcommand not found') |
| 35 | + |
| 36 | +@math.command() |
| 37 | +async def add(ctx, a: int, b: int): |
| 38 | + ... |
| 39 | + |
| 40 | +@math.command() |
| 41 | +async def subtract(ctx, a: int, b: int): |
| 42 | + ... |
| 43 | +``` |
| 44 | + |
| 45 | +To create a command group, the command's decorator must be `@bot.group`. Once you have a command with |
| 46 | +that decorator, you can use `@function.command()`, such as `@math.command()`. Now, you have subcommand |
| 47 | +groups! |
| 48 | + |
| 49 | +<!-- Waiting for slash command groups in Pycord --> |
| 50 | + |
| 51 | +:::info Related Topics |
| 52 | + |
| 53 | +- [Prefixed Commands](./prefixed-commands.mdx) |
| 54 | +- [Cogs](../../popular-topics/cogs) |
| 55 | + |
| 56 | +::: |
0 commit comments