I’ve been messing with bots for a couple days now, and I’m trying to get the name of the user that called a certain command, then be able to use that later on in a different command. I’ve tried using context.author, as in the example below, but it doesn’t seem to work.
JavaScript
x
12
12
1
client = commands.Bot(command_prefix="!")
2
3
@client.command()
4
async def help(ctx):
5
await ctx.send("Test string")
6
variable = context.user
7
#variable is updated each time help function is called
8
9
@client.command()
10
async def get_user(ctx):
11
await ctx.send(variable)
12
Advertisement
Answer
You can just use a global variable.
JavaScript
1
13
13
1
variable = ""
2
3
@client.command()
4
async def help(ctx):
5
global variable
6
await ctx.send("Test string")
7
variable = str(ctx.author.name)
8
9
@client.command()
10
async def get_user(ctx):
11
global variable
12
await ctx.send(variable)
13