File size: 1,219 Bytes
4311475
 
b2a3792
79f8fbd
4311475
 
 
b2a3792
 
 
 
79f8fbd
 
 
 
 
 
 
 
 
 
 
 
 
 
4311475
 
 
 
 
79f8fbd
 
 
4311475
 
 
6c15881
b2a3792
4311475
b2a3792
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import discord
from discord import app_commands
import json
import os

user_cash = {}

def save_database():
    with open("database.txt", "w") as f:
        json.dump(user_cash, f)

def load_database():
    global user_cash
    if os.path.exists("database.txt"):
        try:
            with open("database.txt", "r") as f:
                loaded_data = json.load(f)
                user_cash = {int(k): v for k, v in loaded_data.items()}
        except json.JSONDecodeError:
            print("errer")

# Load the database when the module is imported
load_database()

@app_commands.command(name="cash", description="cash")
async def cash(interaction: discord.Interaction):
    user_id = interaction.user.id
    balance = user_cash.get(user_id, 0)

    if balance == 0:
        user_cash[user_id] = 1000
        balance = 1000
        message = "you are too poor so here is $1000"
    else:
        message = f"Your current balance is ${balance:.2f}"

    embed = discord.Embed(title="Cash Balance", description=message, color=0x787878)
    embed.set_footer(text="Use /dice to bet your cash!")

    await interaction.response.send_message(embed=embed)
    save_database()  # Save the database after each cash operation