Skip to content

Commit

Permalink
docs: slash command groups in cogs
Browse files Browse the repository at this point in the history
  • Loading branch information
JustaSqu1d authored May 29, 2024
1 parent 25ed720 commit 6f12c94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/interactions/application-commands/slash-commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ Here's what the registered subcommands will look like in the Slash Command Menu:

You'll notice that there's the name of the Slash Command Group and then the name of the subcommand separated by a space.

:::

:::info Cogs

If you are looking to add Slash Command Groups to cogs, please look at our [Cogs page](../../popular-topics/cogs)!

:::

## Sub-groups

We've made a subcommand group, but did you know that you could create a group inside another?
Expand All @@ -143,6 +151,8 @@ The command created above can be invoked by typing `/math advanced square_root`.

Whenever you're using Slash Commands, you might notice that you can specify parameters that the user has to set or can optionally set. These are called Options.

Options can also include a description to provide more information. [You can learn more about Options in our documentation!](https://docs.pycord.dev/en/stable/api/application_commands.html#discord.Option)

Since you want different inputs from Options, you'll have to specify the type for that Option; there are a few ways of doing this.

<Tabs>
Expand Down
17 changes: 17 additions & 0 deletions docs/popular-topics/cogs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ class Greetings(commands.Cog): # create a class for our cog that inherits from c
async def greet(self, ctx, member: discord.Member):
await ctx.respond(f'{ctx.author.mention} says hello to {member.mention}!')

math = discord.SlashCommandGroup("math", "Spooky math stuff") # create a Slash Command Group called "math"
advanced_math = math.create_subgroup(
"advanced",
"super hard math commands!"
)

@math.command()
async def add(self, a: int, b: int):
c = a + b
await ctx.respond(f"{a} + {b} is {c}.")

@advanced_math.command()
async def midpoint(self, x1: float, y1: float, x2: float, y2: float):
mid_x = (x1 + x2)/2
mid_y = (y1 + y2)/2
await ctx.respond(f"The midpoint between those coordinates is ({mid_x}, {mid_y}).")

@commands.Cog.listener() # we can add event listeners to our cog
async def on_member_join(self, member): # this is called when a member joins the server
# you must enable the proper intents
Expand Down

0 comments on commit 6f12c94

Please sign in to comment.