Ask coding questions

← Back to all posts
2
How do I make a currency system?
CallumDisney (1)

Can someone please tell me how to make a Discord bot currency system?! I’ve searched EVERYWHERE for an answer! I’m using Python on Repl.it. Someone please tell me how to make a currency system!

I have asked on Reddit before, and people just told me to use json files or SQLite. Now, I have no idea how to use these things. Can someone please tell me how to use them, or, even better, give me some code that I can use to make a currency system.

Amjad Masad sent me here. Thanks.

Commentshotnewtop
2
AllAwesome497 (80)

So here is how u store data in a file:https://repl.it/talk/learn/How-to-store-and-read-an-item-in-a-file-Python-3-works-with-2/12134
So depending on how u wanna store it it:
If u want to save currency per user per server, have it store in the dictionary as:

{
  <server id>: {
    <user Id>: <balance>}}

or if u want a user to have data cross-server:

{
  <user id>: <balance>
}

If u have any more questions, or would like a better example, feel free to reply. Please mark as correct if this solves your question.

2
mat1 (2241)

You could use JSONStore.io to easily save user data (such as currency) in Python. I suggest using @leon332157's library to do this https://repl.it/talk/share/JSONStore/10956

1
ash15khng (208)

You need to store the users data in a file (if you don't want to use SQLite or JSON or stuff like that)
You can do it like this:

with open("file.txt", "a") as f: #"a" means append
   f.write("whatever you want")