You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在discord.py中为命令参数添加描述?

为discord.py命令参数添加描述的方法

要给命令的参数添加描述,让帮助命令能显示参数说明,有两种常用方法,对应不同版本的discord.py:

方法一:使用@commands.param装饰器(v2.0+版本推荐)

直接在参数定义时通过commands.param指定描述,默认值也可以在这里设置,示例代码如下:

@bot.command(description='command do some stuff')
async def somecommand(
    ctx: commands.Context,
    arg1: str = commands.param(description="需要拼接的第一个字符串"),
    arg2: str = commands.param(default="hello", description="需要拼接的第二个字符串,默认值为hello")
):
    await ctx.channel.send(arg1 + arg2)

方法二:手动设置params属性(兼容旧版本)

如果使用的是discord.py旧版本,可以在命令定义完成后,通过修改命令的params属性来添加参数描述:

@bot.command(description='command do some stuff')
async def somecommand(ctx: commands.Context, arg1:str, arg2:str = "hello"):
    await ctx.channel.send(arg1+arg2)

# 为参数添加描述
somecommand.params["arg1"].description = "需要拼接的第一个字符串"
somecommand.params["arg2"].description = "需要拼接的第二个字符串,默认值为hello"

设置完成后,调用!help somecommand或对应前缀的帮助命令时,就能看到每个参数的详细描述了。

内容的提问来源于stack exchange,提问作者Glaurung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 11:35:30