我无法理解如何让用户在命令中下注 X 量的“XP”(我使用美元)。我在下面发布了简单的 coinflip 命令,其中包含我认为应该是逻辑的内容,但我不能 100% 确定我是否在正确的轨道上。我想知道当用户下注随机数量的钱时,如何为用户调用 get_dollars。我猜我将需要创建诸如betamount = enter authors bet amount但我在如何处理他们可能放置的随机数量而不是硬编码强制用户使用的固定数量上画一个空白的东西。
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)
慕的地6264312
相关分类