Ask coding questions

← Back to all posts
how can i take input for cooldowns?
chinnupavan48 (0)

i want to load an integer value from a json file using
how can i pass this in
@commands.cooldown(1, value from json file, commands.BucketType.user)

Coder100 (18934)

I recommend using replit db instead for this job as json files do reset. It may not be today, but it will happen!

Anyways, here is the db version:

from replit import db

def someFunctionToAddCooldown(id, amt):
  db[id] = amt

def getCooldownFromUser(id):
  return db[id]
chinnupavan48 (0)

@commands.cooldown(1, 21600, commands.BucketType.user)
how can i apply for this in place of 21600

Coder100 (18934)

@commands.cooldown(1, db[... id ...], commands.BucketType.user) @chinnupavan48

VulcanWM (2912)
import json
with open('example.json', 'r') as myfile:
obj = json.loads(data)
cooldown = obj.get(userid, None)
# if the userid has a cooldown, it will be the variable, if not, it will be equal to None

This is the code to get the cooldown value from the json file

chinnupavan48 (0)

my qn is
every user has 0 or 1 value in json file
so if user has 0 value then cooldown will be 6 mins
else if user has 1 value then cooldown will be 3 mins

VulcanWM (2912)

then you can do:

if cooldown == 0:
  cooldownvalue = 6
  cooldownvalue = 3


chinnupavan48 (0)


    @commands.cooldown(1, 21600, commands.BucketType.user)
    async def mining(self, ctx: commands.Context):
        await"Mining started now ! " +
        await asyncio.sleep(21600)

        await open_account(
        user =
        users = await get_bank_data()
        staff = users[str(]["staff"]
        if staff == 0:
            d = random.randint(0, 5)
            g = random.randint(5, 20)
            s = random.randint(20, 100)
            d = random.randint(10, 30)
            g = random.randint(20, 80)
            s = random.randint(100, 200)

        users[str(]["diamonds"] += d
        users[str(]["gold"] += g
        users[str(]["silver"] += s

   + "\nYour mining has done! you got\n`Diamonds :{0}`\n`Gold :{1}`\n`Silver :{2}`".format(
                d, g, s))

        with open("bank.json", "w") as f:
            json.dump(users, f)```

see here i gave 21600 in cooldown but first i want to check if the user has 1 or 0 value in json file ...if he has value 1 then i want that cooldown for 21600//2