Multi word discord slash commands (PyCord)

Question:

I’m making a simple set of slash commands using pycord for discord.

import discord


bot = discord.Bot()

testingServer = [{server ID}]

@bot.slash_command(guild_ids = testingServer, name ="verify_help", description="blabla" )
async def verifyHelp(ctx):

    embed=discord.Embed(title="Verify Your Wallet", description = "help goes here",color=0xffffff)


    await ctx.respond(embed = embed, ephemeral=True)

bot.run({TOKEN})

I believe it’s possible to create multi word slash commands as seen in discords API docs:

ie have the slash command as /verify help rather than /verify-help

https://discord.com/developers/docs/interactions/application-commands

I believe i need to translate the "Options" section into pycord but have no idea on the syntax. It suggest and options list so options = []. Which is where i am stuck.

The pycord manual for slashcommand is here: https://docs.pycord.dev/en/master/api.html#slashcommand

Asked By: LegionOfBrad

||

Answers:

Explanation

What you’re looking for are slash command groups. You would create a SlashCommandGroup, then instead of the standard bot.slash_command, you would use SlashCommandGroup.command.

The code below shows an example with /verify help

Code

verify = bot.create_group(name="verify", description="testing", guild_ids=[703732969160048731])


@verify.command(name="help", description="help me pls")
async def verify_help(inter: discord.Interaction):
    print("Hello? How are you? I am under the water, please help me")

Note: In a cog, you would instantiate the SlashCommandGroup through its constructor, not through bot.create_group. Also, the slash command would take in self as its first parameter and an Interaction as its second.

Reference

SlashCommandGroup

Slash Group Example

Slash Groups In Cogs

Answered By: TheFungusAmongUs