Spaces:
Building
Building
Update roulette.py
Browse files- roulette.py +12 -11
roulette.py
CHANGED
@@ -17,17 +17,19 @@ async def play_roulette(interaction: discord.Interaction, bet: int, choice: str)
|
|
17 |
return
|
18 |
|
19 |
if bet > balance:
|
20 |
-
await interaction.response.send_message(f"
|
21 |
return
|
22 |
|
23 |
-
|
24 |
-
|
|
|
25 |
return
|
26 |
|
27 |
-
embed = discord.Embed(title="Roulette Game", description=f"{interaction.user.name} is betting ${bet:.2f}
|
|
|
28 |
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
|
29 |
|
30 |
-
spin_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin the Roulette", custom_id="spin_roulette")
|
31 |
|
32 |
async def spin_roulette_callback(interaction: discord.Interaction):
|
33 |
nonlocal balance
|
@@ -35,12 +37,13 @@ async def play_roulette(interaction: discord.Interaction, bet: int, choice: str)
|
|
35 |
result_color = "green" if result_number == 0 else ("red" if result_number % 2 == 1 else "black")
|
36 |
|
37 |
win = False
|
|
|
38 |
if choice.isdigit():
|
39 |
win = int(choice) == result_number
|
40 |
-
payout = bet * 35 if win else
|
41 |
else:
|
42 |
win = choice == result_color
|
43 |
-
payout = bet * 2 if win else
|
44 |
|
45 |
balance += payout
|
46 |
user_cash[user_id] = balance
|
@@ -52,7 +55,7 @@ async def play_roulette(interaction: discord.Interaction, bet: int, choice: str)
|
|
52 |
embed.add_field(name="Result", value=result_text, inline=False)
|
53 |
embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
|
54 |
|
55 |
-
spin_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin Again", custom_id="spin_again")
|
56 |
|
57 |
async def spin_again_callback(interaction: discord.Interaction):
|
58 |
if interaction.user.id == user_id:
|
@@ -75,6 +78,4 @@ async def play_roulette(interaction: discord.Interaction, bet: int, choice: str)
|
|
75 |
if interaction.response.is_done():
|
76 |
await interaction.followup.send(embed=embed, view=view)
|
77 |
else:
|
78 |
-
await interaction.response.send_message(embed=embed, view=view)
|
79 |
-
|
80 |
-
# Ensure you have set up your bot and registered this command appropriately in your bot setup code.
|
|
|
17 |
return
|
18 |
|
19 |
if bet > balance:
|
20 |
+
await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")
|
21 |
return
|
22 |
|
23 |
+
valid_choices = ["red", "black", "green"] + [str(i) for i in range(37)]
|
24 |
+
if choice not in valid_choices:
|
25 |
+
await interaction.response.send_message("Invalid choice. Choose 'red', 'black', 'green', or a number between 0 and 36.")
|
26 |
return
|
27 |
|
28 |
+
embed = discord.Embed(title="Roulette Game", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x787878)
|
29 |
+
embed.add_field(name="Your Bet", value=f"Choice: {choice}", inline=False)
|
30 |
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
|
31 |
|
32 |
+
spin_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin the Roulette 🎡", custom_id="spin_roulette")
|
33 |
|
34 |
async def spin_roulette_callback(interaction: discord.Interaction):
|
35 |
nonlocal balance
|
|
|
37 |
result_color = "green" if result_number == 0 else ("red" if result_number % 2 == 1 else "black")
|
38 |
|
39 |
win = False
|
40 |
+
payout = -bet
|
41 |
if choice.isdigit():
|
42 |
win = int(choice) == result_number
|
43 |
+
payout = bet * 35 if win else payout
|
44 |
else:
|
45 |
win = choice == result_color
|
46 |
+
payout = bet * 2 if win else payout
|
47 |
|
48 |
balance += payout
|
49 |
user_cash[user_id] = balance
|
|
|
55 |
embed.add_field(name="Result", value=result_text, inline=False)
|
56 |
embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
|
57 |
|
58 |
+
spin_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin Again 🔄", custom_id="spin_again")
|
59 |
|
60 |
async def spin_again_callback(interaction: discord.Interaction):
|
61 |
if interaction.user.id == user_id:
|
|
|
78 |
if interaction.response.is_done():
|
79 |
await interaction.followup.send(embed=embed, view=view)
|
80 |
else:
|
81 |
+
await interaction.response.send_message(embed=embed, view=view)
|
|
|
|