Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from discord.ext import commands
- import json
- bot = commands.Bot('!')
- amounts = {}
- @bot.event
- async def on_ready():
- global amounts
- try:
- with open('amounts.json') as f:
- amounts = json.load(f)
- except FileNotFoundError:
- print("Could not load amounts.json")
- amounts = {}
- @bot.command(pass_context=True)
- async def balance(ctx):
- id = ctx.author.id
- if id in amounts:
- await bot.say("You have {} in the bank".format(amounts[ctx.author.id]))
- else:
- await bot.say("You do not have an account")
- @bot.command(pass_context=True)
- async def register(ctx):
- id = ctx.author.id
- if id not in amounts:
- amounts[id] = 100
- await bot.say("You are now registered")
- else:
- await bot.say("You already have an account")
- @bot.command(pass_context=True)
- async def transfer(ctx, amount: int, other: discord.Member):
- primary_id = ctx.author.id
- other_id = other.id
- if primary_id not in amounts:
- await bot.say("You do not have an account")
- elif other_id not in amounts:
- await bot.say("The other party does not have an account")
- elif amounts[primary_id] < amount:
- await bot.say("You cannot afford this transaction")
- else:
- amounts[primary_id] -= amount
- amounts[other_id] += amount
- await bot.say("Transaction complete")
- @bot.command()
- async def save():
- with open('amounts.json', 'w+') as f:
- json.dump(amounts, f)
- bot.run("TOKEN")
Add Comment
Please, Sign In to add comment