多字不一致斜杠命令 (PyCord)

Leg*_*rad 3 python slash discord discord.py pycord

我正在使用 pycord 制作一组简单的斜杠命令来实现不和谐。

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})

Run Code Online (Sandbox Code Playgroud)

我相信可以创建多字斜线命令,如不和谐 API 文档中所示:

即使用斜杠命令作为 /verify help 而不是 /verify-help

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

我相信我需要将“选项”部分翻译成 pycord 但不知道语法。它建议并列出选项,因此 options = []。这就是我被困住的地方。

lashcommand 的 pycord 手册在这里:https ://docs.pycord.dev/en/master/api.html#slashcommand

The*_*gUs 5

解释

您正在寻找的是斜线命令组。您将创建一个SlashCommandGroup,然后bot.slash_command使用SlashCommandGroup.command.

下面的代码显示了一个示例/verify help

代码

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")
Run Code Online (Sandbox Code Playgroud)

注意:在 cog 中,您可以SlashCommandGroup通过其构造函数而不是通过 来实例化bot.create_group。此外,斜杠命令将接受self作为其第一个参数,并接受 anInteraction作为其第二个参数。

参考

SlashCommandGroup

斜线组示例

齿轮中的斜线组