import discord
import json
import random as rand
from discord.ext import commands
import os
bot = commands.Bot(command_prefix = "!", intents = discord.Intents.all())
bot.remove_command( 'help' )
os.chdir("C:\\Users\\User\\Desktop\\test botik")
@bot.command()
async def balance(ctx):
await open_account(ctx.author)
user = ctx.author
users = await get_bank_data()
wallet_amt = users[str(user.id)]["wallet"] = 0
bank_amt = users[str(user.id)]["bank"] = 0
em = discord.Embed(title = f"{ctx.author.name}'s balance",color = discord.Color.red())
em.add_field(name = "Wallet balance",value = wallet_amt)
em.add_field(name = "Bank balance",value = bank_amt)
await ctx.send(embed = em)
@bot.command()
async def beg(ctx):
await open_account(ctx.author)
users = await get_bank_data()
user = ctx.author
earnings = rand.randrange(101)
await ctx.send(f"Кто-то дал тебе {earnings} монет!")
users[str(user.id)]["wallet"] += earnings
with open("mainbank.json","w") as f:
json.dump(users,f)
async def open_account(user):
users = await get_bank_data()
if str(user.id) in users:
return False
else:
users[str(user.id)]["wallet"] = 0
users[str(user.id)]["bank"] = 0
with open("mainbank.json","w") as f:
json.dump(users,f)
return True
async def get_bank_data():
with open("mainbank.json","r") as f:
users = json.load(f)
bot.run("")