'How would I get access to a file I don't know the name of
I might describe this very poorly but here we go. What I am doing is creating a file with the user id from discord. In a different function, I want to access the file but I don't know the name of it
import json
import discord
@client.command()
async def function1(ctx):
test1 = 3
author = ctx.message.author.mention
await ctx.send(author)
with open(author+'.txt', 'w+') as outfile:
json.dump(test1, outfile)
@client.command()
async def function2(ctx):
with open(author+'.txt') as infile: #The "author+'.txt'" does not work because it does not know what author is.
test2 = json.load(infile)
await ctx.send(test2)
How would I get around this and access this file? I have an idea, I could save the author and then call it in function two. This would not work because there are many people using the bot. Am I on the right track? Thanks for the help in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
