如何在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
相关产品推荐
相关产品推荐

