【问题标题】:How do I add a description to an argument in a Discord slash command (Python)如何在 Discord 斜杠命令 (Python) 中为参数添加描述
【发布时间】:2023-02-22 07:31:52
【问题描述】:

我是 discord.ext 库,使用 @bot.tree.command 装饰器。我发现如果我只使用 @bot.command 装饰器,那么命令不会同步 on_ready。我已经为命令本身添加了描述,但我想为它接受的可选参数添加描述。代码如下。

@client.tree.command(name="command", description="test command")
async def scores(interaction: discord.Interaction, date: str=datetime.now(tz).strftime('%Y-%m-%d')):
    await interaction.response.send_message(str("\n".join(testcommand.getinfo(date))))

我看到 this post 展示了如何做到这一点,但它只适用于 @bot.command 装饰器。用@bot.tree.command 尝试失败。

【问题讨论】:

    标签: discord


    【解决方案1】:

    我已经弄清楚我自己的问题了!有一个装饰器可以做到这一点。

    @discord.app_commands.describe(date = "Date in YYYY-MM-DD format")

    【讨论】:

      【解决方案2】:

      或者,您可以使用文档字符串为您的命令和参数添加描述

      例子

      @app_commands.command(name="my_command")
      async def command(interaction: Interaction, a: int, b: str):
          """my command description
      
          Args:
              x (int): my first parameter description
              b (str): my second parameter description
          """
          pass
      

      【讨论】:

        猜你喜欢
        • 2022-12-05
        • 1970-01-01
        • 1970-01-01
        • 2021-10-23
        • 2021-12-31
        • 1970-01-01
        • 1970-01-01
        • 2021-10-19
        • 2015-03-25
        相关资源
        最近更新 更多