我正在使用 Discord.py 编写配置文件命令,它打印出有关指定用户的信息。
我想将消息作者作为默认参数传递,因此如果用户只写命令而没有其他任何内容,机器人将发送他们的个人资料。
@bot.command()
async def profile(ctx, *, user: discord.Member = ctx.message.author):
上面的代码不起作用。它因以下错误而出错:
Traceback (most recent call last):
File "bot.py", line 50, in <module>
async def profile(ctx, *, user: discord.Member = ctx.message.author.name):
NameError: name 'ctx' is not defined
谁能告诉我我做错了什么以及如何让我的代码工作?
编辑:
我有点绕过了这个问题:
@bot.command()
async def profile(ctx, *, user: discord.Member=None):
if(user == None):
user = ctx.message.author
我的问题仍然存在,有没有办法将 ctx 作为默认参数传递?
MM们
慕码人2483693
相关分类