Skip to content
← Back to Community
(discord.py) Economy data - Replit DB?
Profile icon
meziosaur

Hello
I needed some guidance, I wanted to save 4 kinds of currencies per user into a replitDB.

I'm kinda lost and not sure where to start with it.
Would I need a key per user like so:
(User_id)(coin_id)=amount

It's this the right train of thought?

Voters
Profile icon
meziosaur
Comments
hotnewtop
Profile icon
OldWizard209

You will need to save a dictionary as a value to the username's key"

from replit import db user_name = "SomeUsername" # Put user's name to variable user_amount_usd = 1000 # Put user's amount to variable db[user_name] = { "amount_economy": { "dollar_amount" : user_amount_usd, "pounds_amount" : user_amount_usd*0.72, # Converting US Dollars to UK Pounds. "indian_rupees" : user_amount_usd*74.23, # Converting US Dollars to Indian Rupees. "chinese_yuan" : user_amount_usd*6.46 # Converting US Dollars to Chinese Yuan. } } user_amount = db[user_name]["amount_economy"] print(f"{user_name}'s amount in Pounds is {user_amount['pounds_amount']}")
Profile icon
Coder100

How about this:

db[user id] = { 'currency1': ... 'currency2': ... 'currency3': ... ... }

remember to treat it like a dict.

Profile icon
OldWizard209

Are you sure you can access a value in a dictionary in Python using a dot notation? You are using the concept of JavaScript Objects in this example:

db[user.id]
@Coder100

Profile icon
Coder100

well it was a semantic example after all @OldWizard209

Profile icon
Coder100

but from what i can tell id is a property of the class user @OldWizard209

Profile icon
OldWizard209

Well if it is a property then you were right but as a general example, it should be best to do db[user][id]. Also, the user(question asker) said they were using multiple currencies so it would be better to save a dictionary as a value in the db, containing all the currencies.
@Coder100

Profile icon
Coder100

yes that is what i did did you not see @OldWizard209