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

如何在discord.py中为makeprofile命令设置参数描述

解决方法

在discord.py中,要给命令参数添加自定义描述,有两种常用实现方式:

方式一:使用app_commands.describe()装饰器

通过该装饰器可以批量为多个参数设置描述,代码结构更清晰:

import discord
from discord import app_commands

@tree.command(name="makeprofile", description="Make your own profile!", guild=discord.Object(id=000000000000))
@app_commands.describe(
    preferred_name="你想被称呼为什么?",
    pronouns="你的人称代词(例如:他/他、她/她等)"
)
async def make_profile(interaction, preferred_name: str, pronouns: str):
    db.insert({'id': interaction.user.id, 'name': preferred_name, 'pronouns': pronouns})

方式二:使用app_commands.Parameter直接指定

这种方式可以在参数定义时单独设置描述,适合只需要修改单个参数的场景:

import discord
from discord import app_commands

@tree.command(name="makeprofile", description="Make your own profile!", guild=discord.Object(id=000000000000))
async def make_profile(
    interaction,
    preferred_name: str = app_commands.Parameter(description="你想被称呼为什么?"),
    pronouns: str
):
    db.insert({'id': interaction.user.id, 'name': preferred_name, 'pronouns': pronouns})

两种方式都能实现为preferred_name参数添加指定描述的效果,可根据个人习惯选择。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 22:15:30