Spaces:
Building
Building
Update cash.py
Browse files
cash.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import discord
|
2 |
from discord import app_commands
|
3 |
import json
|
|
|
4 |
|
5 |
user_cash = {}
|
6 |
|
@@ -8,15 +9,28 @@ def save_database():
|
|
8 |
with open("database.txt", "w") as f:
|
9 |
json.dump(user_cash, f)
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
async def cash(interaction: discord.Interaction):
|
13 |
user_id = interaction.user.id
|
14 |
balance = user_cash.get(user_id, 0)
|
15 |
|
16 |
if balance == 0:
|
17 |
-
user_cash[user_id] =
|
18 |
-
balance =
|
19 |
-
message = "you are too poor so here is $
|
20 |
else:
|
21 |
message = f"Your current balance is ${balance:.2f}"
|
22 |
|
|
|
1 |
import discord
|
2 |
from discord import app_commands
|
3 |
import json
|
4 |
+
import os
|
5 |
|
6 |
user_cash = {}
|
7 |
|
|
|
9 |
with open("database.txt", "w") as f:
|
10 |
json.dump(user_cash, f)
|
11 |
|
12 |
+
def load_database():
|
13 |
+
global user_cash
|
14 |
+
if os.path.exists("database.txt"):
|
15 |
+
try:
|
16 |
+
with open("database.txt", "r") as f:
|
17 |
+
loaded_data = json.load(f)
|
18 |
+
user_cash = {int(k): v for k, v in loaded_data.items()}
|
19 |
+
except json.JSONDecodeError:
|
20 |
+
print("errer")
|
21 |
+
|
22 |
+
# Load the database when the module is imported
|
23 |
+
load_database()
|
24 |
+
|
25 |
+
@app_commands.command(name="cash", description="cash")
|
26 |
async def cash(interaction: discord.Interaction):
|
27 |
user_id = interaction.user.id
|
28 |
balance = user_cash.get(user_id, 0)
|
29 |
|
30 |
if balance == 0:
|
31 |
+
user_cash[user_id] = 1000
|
32 |
+
balance = 1000
|
33 |
+
message = "you are too poor so here is $1000"
|
34 |
else:
|
35 |
message = f"Your current balance is ${balance:.2f}"
|
36 |
|