【问题标题】:Multi word discord slash commands (PyCord)Multi word discord slash commands (PyCord)
【发布时间】:2022-11-09 11:25:41
【问题描述】:

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

    标签: python discord discord.py slash pycord


    【解决方案1】:

    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

      猜你喜欢
      • 2022-12-02
      • 2023-01-29
      • 1970-01-01
      • 2022-07-18
      • 2021-06-28
      • 2021-06-28
      • 2021-04-06
      • 1970-01-01
      • 2022-11-28
      相关资源
      最近更新 更多