python - 多字 discord 斜杠命令 (PyCord)

标签 python discord discord.py slash pycord

我正在使用 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 作为第二个参数。

引用

SlashCommandGroup

Slash Group Example

Slash Groups In Cogs

关于python - 多字 discord 斜杠命令 (PyCord),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71166643/

相关文章:

python - discord.py `SSL certificate verify failed` 错误

python - 尝试传递字符串以通过 Django Rest Framework url 进行查询

python - 监督机器学习 : Classify types of clusters of data based on shape and density (Python)

python - 如何通过 Pandas 中特定列的计算添加行

java - 在本地同时运行 Java 和 Python 标准

python - 使用python在discord上抓取数据

python - Discord.py on_member_join 不工作,没有错误信息

python - (discord.py) 齿轮中的函数

javascript - Discord JS 发送数据这样的图像

python - Python Bot 中的子命令