如何解决如何获取命令的最新调用,并将其保存在函数中?
我已经把僵尸弄了两天了,我正在尝试获取调用某个命令的用户的名称,然后以后可以在另一个命令中使用它。我已经尝试过使用context.author,如下面的示例所示,但是它似乎不起作用。
client = commands.Bot(command_prefix="!")
@client.command()
async def help(ctx):
await ctx.send("Test string")
variable = context.user
#variable is updated each time help function is called
@client.command()
async def get_user(ctx):
await ctx.send(variable)
解决方法
您可以只使用全局变量。
variable = ""
@client.command()
async def help(ctx):
global variable
await ctx.send("Test string")
variable = str(ctx.author.name)
@client.command()
async def get_user(ctx):
global variable
await ctx.send(variable)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。