Here I ask the user to Gamble and when the user's answer gets correct the code adds 1 to the database but I don't know how to keep on adding when the user gets it correct for the second time like 1 then 2 then 3 and so on. So, can someone please help me with this
import discord
from discord.ext import commands
import random
import json
clients = commands.Bot(command_prefix='!')
Bot = discord.Client()
json_file = set()
@Bot.event
async def on_ready():
print('ready')
@clients.command()
async def Gamble(ctx, num):
number = random.randint(1,3)
if int(num) == number:
await ctx.send("Congratulations! you won 1 Tes")
json_file.add(1)
print(json_file)
if int(num) != number:
await ctx.send('Better luck next time')
print(json_file)
client.run('TOKEN')
CodePudding user response:
I hope I understood clearly, but you want a counter as the "database" (in this case the json_file
set).
What about user a variable counter = 0
and then every time the answer is correct, just increment it counter = counter 1
.
If however, you just want to have a list of ones, change json_file
to a list (json_file = []
) and then append 1 instead of add
(json_file.append(1)
). I hope that helps. If not, just explain a little bit further what you are trying to achieve, and I am sure an answer will be found.