Spaces:
Building
Building
File size: 938 Bytes
ebb0b1d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import discord
from discord import app_commands
import json
from cash import user_cash
@app_commands.command(name="database", description="database")
@app_commands.describe(action="save or load'")
async def database(interaction: discord.Interaction, action: str):
if action.lower() == "save":
with open("database.txt", "w") as f:
json.dump(user_cash, f)
await interaction.response.send_message("saved to database.txt")
elif action.lower() == "load":
try:
with open("database.txt", "r") as f:
loaded_data = json.load(f)
user_cash.clear()
user_cash.update(loaded_data)
await interaction.response.send_message("Database from database.txt")
except FileNotFoundError:
await interaction.response.send_message("AAAAAAAAAA.")
else:
await interaction.response.send_message("Use 'save' or 'load'.") |