如何使用上下文在同一行中定义上下文来设置默认值? [英] How to set a default using context with context defined in same line?

查看:28
本文介绍了如何使用上下文在同一行中定义上下文来设置默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个不和谐的bot,并且尝试使其在以下位置进行操作:如果成员说出一个未提及用户的命令,则该命令默认为他们自己.它不能内联工作,我需要在同一行中使用arg.

I am creating a discord bot, and I am trying to make it where if a member says a command with no user mentioned, it defaults to themself. It doesn't work inline, and I need the arg in the same line.

我尝试将默认值放在同一行中,但是我需要ctx,并且ctx在同一行中定义,因此它将无法正常工作.

I tried to put the default in the same line, but I need the ctx for that, and ctx is defined in the same line, so it won't work.

@bot.command(name="joined", description="Shows precisely when a member of the server joined", aliases=["entry", "jointime", "join_time"], pass_context=True)
async def joined(**ctx**, member: discord.Member = **ctx.message.author.name**):
    """Says when a member joined."""
    await ctx.send('{0.name} joined in {0.joined_at}'.format(member))

当您说加入"或进入"而没有提及用户时,我希望这能使用户脱离上下文并使用该用户.但是,它向我抛出错误消息未定义ctx."

I expected this, when you say !joined or !entry, with no user mention, to take the user from the context and use that instead. However, it throws me the error message "ctx is not defined."

推荐答案

您可以标记参数

这篇关于如何使用上下文在同一行中定义上下文来设置默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆