I can't wrap my head around how to let a user bet X amount of "XP"(i use dollars) inside of a command. I've posted the simple coinflip command below with what I think should be the logic, but I am not 100% sure if I'm on the right track. I was wondering how I could call get_dollars for the user when they bet a random amount of money. I'm guessing that I will need to create something such as betamount = enter authors bet amount
but I'm drawing a blank on how to handle the random amount they may put rather than hardcoding a fixed amount that forces the user to use.
client = discord.Client()
try:
with open("cash.json") as fp:
cash = json.load(fp)
except Exception:
cash = {}
def save_cash():
with open("cash.json", "w+") as fp:
json.dump(cash, fp, sort_keys=True, indent=4)
def get_dollars(user: discord.User):
id = user.id
if id in cash:
return cash[id].get("dollars", 0)
return 0
@client.event
async def on_message(message):
betamount = ???
if message.content.lower().startswith('!coinflip'):
if get_dollars(message.author) < 0:
await client.send_message(message.channel, "{} you don't have enough money to bet.".format(message.author.mention))
else:
choice = random.randint(0,1)
if choice == 0
await client.add_reaction(message, '⚫')
await client.send_message(message.channel, "The coin handed on heads!)
if 'heads' in message.content:
await client.send_message(message.channel, "You've won ${}".format(betamount))
add_dollars(message.author, betamount)
else:
if 'tails' in message.content:
await client.send_message(message.channel, "You've lost ${}".format(betamount))
remove_dollars(message.author, betamount)
elif choice == 1:
await client.add_reaction(message, '⚪')
await client.send_message(message.channel, "The coin handed on tails!")
if 'tails' in message.content:
await client.send_message(message.channel, "You've won ${}".format(betamount))
add_dollars(message.author, betamount)
else:
if 'heads' in message.content:
await client.send_message(message.channel, "You've lost ${}".format(betamount))
remove_dollars(message.author, betamount)