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.
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)
Advertisement
Answer
You can just use a global 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)