Reputation: 13
The discord user types .findtest and if certain critia is met, asks them a question. I need to save the response. For some reason the "response" getting saved is their initial ".findtest" that they typed. Would appreciate any help. Thanks.
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True, pass_content=True)
async def findtest(self, ctx):
discord_id = str(ctx.message.author.id)
with open(("C:/Users/Administrator/Desktop/DATABASE/test.json")) as f:
data = json.load(f)
if discord_id in data:
await self.bot.say("User Found, Finding Game")
#more code to come#
else:
await self.bot.say('Type in your Display Name exactly as it appears')
async def on_message(message, ctx, pass_context=True, pass_content=True):
message_d= str(ctx.message.content)
k = {(discord_id): message_d}
with open("C:/Users/Administrator/Desktop/DATABASE/test.json") as f:
data = json.load(f)
data.update(k)
with open("C:/Users/Administrator/Desktop/DATABASE/test.json", 'w') as f:
json.dump(data, f)
Upvotes: 0
Views: 26
Reputation: 60994
Use Client.wait_for_message
to get the users response to your question. It would also make more sense for your bot to remember the contents of data
and only open the file to update it when those contents change:
class Cog:
def __init__(self, bot):
self.bot = bot
self.path = "C:/Users/Administrator/Desktop/DATABASE/test.json"
with open(self.path) as f:
self.data = json.load(f)
@commands.command(pass_context=True)
async def findtest(self, ctx):
discord_id = str(ctx.message.author.id)
if discord_id in self.data:
await self.bot.say("User Found, Finding Game")
#more code to come#
else:
await self.bot.say('Type in your Display Name exactly as it appears')
response = await self.bot.wait_for_message(author=ctx.message.author,
channel=ctx.message.channel)
message_d = response.content
k = {(discord_id): message_d}
self.data.update(k)
with open(self.path, 'w') as f:
json.dump(self.data, f)
Upvotes: 1