import discord from discord.ext import commands #from private.config import token import json import os os.chdir("/home/godot/Documents/scripts/discord-bot.py") #os.chdir("/opt/disbot") intents = discord.Intents.default() intents.message_content = True bot = commands.Bot(command_prefix='$', intents=intents) @bot.event # Start succes indicator async def on_ready(): print(f'We have logged in as {bot.user}') @bot.command() # Ahoj function async def ahoj(ctx): await ctx.send("Zdravím miláčkové!") @bot.command() async def balance(ctx): # test if acount is opend and makes on if not await open_account(ctx.author) user = ctx.author users = await get_bank_data() wallet_amt = users[str(user.id)]["wallet"] em = discord.Embed(title = f"{ctx.author.name}'s balance",color = discord.Color.red()) em.add_field(name = "Wallet balance", value = wallet_amt) await ctx.send(embed = em) @bot.command() # Payout command # from who???? TODO! async def payout(ctx,member:discord.Member,amount = None): await open_account(member) if amount == None: await ctx.send("Plese enter the amount") return if check_role(ctx, member) == False: await ctx.send("Good try my man") if check_role(ctx, member): await update_bank(member,amount) await ctx.send(f"You gave {member} {amount} coins!") # TODO! cut async def open_account(user): # opens json file to found if user id is present users = await get_bank_data() # tests presence if str(user.id) in users: return False else: users[str(user.id)] = {} users[str(user.id)]["wallet"] = 100 # saves a new data in json with open("mainbank.json", "w") as f: json.dump(users,f) return True # opens json stored data async def get_bank_data(): with open("mainbank.json", "r") as f: users = json.load(f) return users async def update_bank(user,change = 0): users = await get_bank_data() users[str(user.id)]["wallet"] += int(change) with open("mainbank.json", "w") as f: json.dump(users,f) bal = [users[str(user.id)]["wallet"]] return bal async def check_role(ctx, user:discord.Member): role = discord.utils.get(ctx.guild.roles,name = "Učitelé") if role in user.roles: return True else: return False