我正在使用 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})
我相信可以创建多词斜杠命令,如 discords API 文档所示:
即斜杠命令作为/verify help 而不是/verify-help
https://discord.com/developers/docs/interactions/application-commands
我相信我需要将“选项”部分翻译成 pycord 但不知道语法。它建议和选项列表所以选项 = []。这就是我被困的地方。
slashcommand 的 pycord 手册在这里:https://docs.pycord.dev/en/master/api.html#slashcommand
最佳答案
解释
您正在寻找的是斜杠命令组。您将创建一个 SlashCommandGroup
,然后您将使用 SlashCommandGroup.command
而不是标准的 bot.slash_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")
注意:在 cog 中,您将通过其构造函数而不是通过 bot.create_group
实例化 SlashCommandGroup
。此外,斜杠命令会将 self
作为第一个参数,将 Interaction
作为第二个参数。
引用
关于python - 多字 discord 斜杠命令 (PyCord),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71166643/