├── mainbank.json ├── README.md └── economy.py /mainbank.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | 4 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Discord-Econmy-bot 2 | simple economy bot made with discord.py with commands like bal,rob,pay,deposit,slots,withdraw 3 | 4 | 5 | 6 | Replace the bot token with your token and enjoyyy 7 | 8 | 9 | Credits : swastik(team mate) 10 | 11 | 12 | Link to my bot : https://discord.com/api/oauth2/authorize?client_id=762955435832901642&permissions=8&scope=bot 13 | -------------------------------------------------------------------------------- /economy.py: -------------------------------------------------------------------------------- 1 | import discord 2 | from discord.ext import commands 3 | import json 4 | import os 5 | import math 6 | import random 7 | 8 | 9 | TOKEN = "Enter your token here" 10 | 11 | 12 | client = commands.Bot(command_prefix = "#") 13 | 14 | 15 | 16 | client.remove_command('help') 17 | 18 | @client.event 19 | async def on_ready(): 20 | await client.change_presence(activity=discord.Game(name="#help")) 21 | print("Bot is ready") 22 | 23 | 24 | @client.command(pass_context=True) 25 | async def bal(ctx): 26 | await open_account(ctx.author) 27 | 28 | user = ctx.author 29 | 30 | users = await get_bank_data() 31 | 32 | wallet_amt = users[str(user.id)]["wallet"] 33 | 34 | bank_amt = users[str(user.id)]["bank"] 35 | 36 | embed = discord.Embed(title=f"{ctx.author.name}'s balance", color=0xFF69B4) 37 | 38 | embed.add_field(name= "Wallet Balance", value= wallet_amt,inline = False) 39 | embed.add_field(name= "Bank Balance", value= bank_amt,inline = False) 40 | 41 | await ctx.send(embed = embed) 42 | 43 | @client.command(pass_context=True) 44 | async def beg(ctx): 45 | await open_account(ctx.author) 46 | 47 | user = ctx.author 48 | 49 | users = await get_bank_data() 50 | 51 | 52 | 53 | 54 | earnings = random.randrange(101) 55 | 56 | await ctx.send(f"**Mochi gave you {earnings} coins!!**") 57 | 58 | users[str(user.id)]["wallet"] += earnings 59 | 60 | with open("mainbank.json", "w") as f: 61 | json.dump(users,f) 62 | 63 | @client.command(pass_context=True) 64 | async def withdraw(ctx,amount = None): 65 | await open_account(ctx.author) 66 | if amount == None: 67 | await ctx.send("**Please enter the amount**") 68 | return 69 | 70 | bal = await update_bank(ctx.author) 71 | 72 | amount = int(amount) 73 | 74 | if amount>bal[1]: 75 | await ctx.send("**You dont have that much money!!**") 76 | return 77 | if amount<0: 78 | await ctx.send("**Amount must be positive**") 79 | return 80 | 81 | await update_bank(ctx.author,amount) 82 | await update_bank(ctx.author,-1*amount,"bank") 83 | 84 | await ctx.send(f"**you withdrew {amount} coins!**") 85 | 86 | @client.command(pass_context=True) 87 | async def dep(ctx,amount = None): 88 | await open_account(ctx.author) 89 | if amount == None: 90 | await ctx.send("**Please enter the amount**") 91 | return 92 | 93 | bal = await update_bank(ctx.author) 94 | 95 | amount = int(amount) 96 | 97 | if amount>bal[0]: 98 | await ctx.send("**You dont have that much money!!**") 99 | return 100 | if amount<0: 101 | await ctx.send("**Amount must be positive**") 102 | return 103 | 104 | await update_bank(ctx.author,-1*amount) 105 | await update_bank(ctx.author,amount,"bank") 106 | 107 | await ctx.send(f"**you deposited {amount} coins!**") 108 | 109 | 110 | @client.command(pass_context=True) 111 | async def pay(ctx,member: discord.Member, amount = None): 112 | await open_account(ctx.author) 113 | await open_account(member) 114 | if amount == None: 115 | await ctx.send("**Please enter the amount**") 116 | return 117 | 118 | bal = await update_bank(ctx.author) 119 | 120 | if amount == "all": 121 | amount = bal[0] 122 | 123 | 124 | 125 | 126 | amount = int(amount) 127 | 128 | if amount>bal[1]: 129 | await ctx.send("**You dont have that much money!!**") 130 | return 131 | if amount<0: 132 | await ctx.send("**Amount must be positive**") 133 | return 134 | 135 | await update_bank(ctx.author,-1*amount,"bank") 136 | await update_bank(member,amount,"bank") 137 | 138 | await ctx.send(f"**you paid {amount} coins!**") 139 | 140 | @client.command(pass_context=True) 141 | async def rob(ctx,member: discord.Member): 142 | await open_account(ctx.author) 143 | await open_account(member) 144 | 145 | bal = await update_bank(member) 146 | 147 | 148 | 149 | if bal[0]<100: 150 | await ctx.send("It's not worth it") 151 | return 152 | 153 | earnings = random.randrange(0, bal[0]) 154 | 155 | 156 | await update_bank(ctx.author,earnings) 157 | await update_bank(member,-1*earnings) 158 | 159 | await ctx.send(f"you robbed and got {earnings} coins!") 160 | 161 | 162 | @client.command(pass_context=True) 163 | async def slots(ctx, amount = None): 164 | await open_account(ctx.author) 165 | if amount == None: 166 | await ctx.send("Please enter the amount") 167 | return 168 | 169 | bal = await update_bank(ctx.author) 170 | 171 | amount = int(amount) 172 | 173 | if amount>bal[0]: 174 | await ctx.send("You dont have that much money!!") 175 | return 176 | if amount<0: 177 | await ctx.send("Amount must be positive") 178 | return 179 | 180 | final = [] 181 | for i in range(3): 182 | a = random.choice([":poop:", ":smile:", ":cherry_blossom:"]) 183 | 184 | final.append(a) 185 | 186 | await ctx.send(str(final)) 187 | 188 | if final[0] == final[1] or final[0] == final[2] or final[2] == final[1]: 189 | await update_bank(ctx.author,2*amount) 190 | await ctx.send("**you won!**") 191 | 192 | else: 193 | await update_bank(ctx.author,-1*amount) 194 | await ctx.send("**you lost!**") 195 | 196 | 197 | async def open_account(user): 198 | 199 | users = await get_bank_data() 200 | if str(user.id) in users: 201 | return False 202 | else: 203 | users[str(user.id)] = {} 204 | users[str(user.id)]["wallet"] = 0 205 | users[str(user.id)]["bank"] = 0 206 | 207 | with open("mainbank.json", "w") as f: 208 | json.dump(users,f) 209 | return True 210 | 211 | 212 | async def get_bank_data(): 213 | with open("mainbank.json", "r") as f: 214 | users = json.load(f) 215 | 216 | return users 217 | 218 | 219 | 220 | async def update_bank(user, change=0,mode = 'wallet'): 221 | 222 | users = await get_bank_data() 223 | 224 | users[str(user.id)][mode] += change 225 | 226 | with open("mainbank.json", "w") as f: 227 | json.dump(users,f) 228 | 229 | bal = users[str(user.id)]["wallet"],users[str(user.id)]["bank"] 230 | 231 | 232 | return bal 233 | 234 | 235 | client.run(TOKEN) 236 | --------------------------------------------------------------------------------