如何在 discord.py bot.command 中将用户调用命令作为默认参数传递?
How to pass the user invoking command as default parameter in discord.py bot.command?
我正在尝试为我的 discord.py
机器人创建一个基于排名的系统。
我想执行一个排名命令,returns 指定用户的排名。默认情况下,我希望指定用户成为调用命令的用户,即 ctx.message.author
.
async def rank(self, ctx, user: discord.Member=ctx.message.author):
我知道这是无效的语法,但我怎样才能做到这一点?
我的 discord.py 版本是 1.7.3
。
谢谢!
我会将 user
默认设置为 None(使用 typing.Optional)并在命令中将其替换为 ctx.message.author。
例如
async def rank(self, ctx, user: typing.Optional[discord.Member]=None):
if not user:
user = ctx.message.author
我正在尝试为我的 discord.py
机器人创建一个基于排名的系统。
我想执行一个排名命令,returns 指定用户的排名。默认情况下,我希望指定用户成为调用命令的用户,即 ctx.message.author
.
async def rank(self, ctx, user: discord.Member=ctx.message.author):
我知道这是无效的语法,但我怎样才能做到这一点?
我的 discord.py 版本是 1.7.3
。
谢谢!
我会将 user
默认设置为 None(使用 typing.Optional)并在命令中将其替换为 ctx.message.author。
例如
async def rank(self, ctx, user: typing.Optional[discord.Member]=None):
if not user:
user = ctx.message.author