discord.py 传递命令参数或在未指定参数时添加值

discord.py passing a commands parameter or adding a value if parameter is not specified

如果用户没有指定参数,我想给参数赋值。我知道 "typing.Optional" 但它没有用(也许我不知道如何使用它)。我试图做的是如果参数为空,分配参数的 ctx 作者。这是我的使用方法:

@client.command()
async def level(ctx, member: typing.Optional = discord.Message.author):

这是我尝试过的其他方法:

@client.command()
async def level(ctx, member: discord.Member):
    if member == None:
        member = ctx.message.author

我也试过了:

@client.command()
async def level(ctx, member: discord.Member = discord.Message.author):

当我 运行 执行此操作时,出现 必需参数 错误。那我该如何解决呢?

Python 包括对默认值的支持,请参阅 here

但是您要寻找的细节是 async def level(ctx, member: discord.Member=None):

这被推荐为答案而不是评论