Spaces:
Paused
Paused
Update roulette.py
Browse files- roulette.py +13 -8
roulette.py
CHANGED
|
@@ -19,9 +19,12 @@ class RouletteView(discord.ui.View):
|
|
| 19 |
@discord.ui.button(label="Spin the Roulette", style=discord.ButtonStyle.primary, custom_id="spin_button")
|
| 20 |
async def spin_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
|
| 21 |
if interaction.user.id != self.user_id:
|
| 22 |
-
await interaction.response.send_message("
|
| 23 |
return
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
result = random.choices(ROULETTE_COLORS, weights=[18, 1, 18], k=1)[0]
|
| 26 |
|
| 27 |
if result == self.choice:
|
|
@@ -44,10 +47,10 @@ class RouletteView(discord.ui.View):
|
|
| 44 |
embed.add_field(name="Result", value=result_text, inline=False)
|
| 45 |
embed.add_field(name="New Balance", value=f"${self.balance:.2f}", inline=False)
|
| 46 |
|
| 47 |
-
# Disable the button after spin
|
| 48 |
self.disable_all_items()
|
| 49 |
|
| 50 |
-
await interaction.
|
| 51 |
|
| 52 |
class RouletteBotClient(discord.Client):
|
| 53 |
def __init__(self):
|
|
@@ -56,14 +59,16 @@ class RouletteBotClient(discord.Client):
|
|
| 56 |
super().__init__(intents=intents)
|
| 57 |
self.tree = app_commands.CommandTree(self)
|
| 58 |
|
| 59 |
-
async def
|
| 60 |
await self.tree.sync()
|
|
|
|
|
|
|
| 61 |
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
| 62 |
print('------')
|
| 63 |
|
| 64 |
client = RouletteBotClient()
|
| 65 |
|
| 66 |
-
@client.tree.command(name="roulette", description="
|
| 67 |
@app_commands.describe(
|
| 68 |
bet="Amount you want to bet",
|
| 69 |
choice="Choose red, green, or black"
|
|
@@ -73,7 +78,7 @@ async def roulette(interaction: discord.Interaction, bet: float, choice: str):
|
|
| 73 |
choice = choice.lower()
|
| 74 |
|
| 75 |
if choice not in ROULETTE_COLORS:
|
| 76 |
-
await interaction.response.send_message("
|
| 77 |
return
|
| 78 |
|
| 79 |
if bet <= 0:
|
|
@@ -83,7 +88,7 @@ async def roulette(interaction: discord.Interaction, bet: float, choice: str):
|
|
| 83 |
balance = user_cash.get(user_id, 1000.0) # Default starting balance
|
| 84 |
|
| 85 |
if bet > balance:
|
| 86 |
-
await interaction.response.send_message(f"
|
| 87 |
return
|
| 88 |
|
| 89 |
# Deduct the bet initially
|
|
@@ -94,4 +99,4 @@ async def roulette(interaction: discord.Interaction, bet: float, choice: str):
|
|
| 94 |
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
|
| 95 |
|
| 96 |
view = RouletteView(user_id, bet, choice, balance)
|
| 97 |
-
|
|
|
|
| 19 |
@discord.ui.button(label="Spin the Roulette", style=discord.ButtonStyle.primary, custom_id="spin_button")
|
| 20 |
async def spin_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
|
| 21 |
if interaction.user.id != self.user_id:
|
| 22 |
+
await interaction.response.send_message("You are not authorized to use this button.", ephemeral=True)
|
| 23 |
return
|
| 24 |
|
| 25 |
+
# Simulate spinning the roulette
|
| 26 |
+
await interaction.response.defer() # Acknowledge the interaction to allow more time
|
| 27 |
+
|
| 28 |
result = random.choices(ROULETTE_COLORS, weights=[18, 1, 18], k=1)[0]
|
| 29 |
|
| 30 |
if result == self.choice:
|
|
|
|
| 47 |
embed.add_field(name="Result", value=result_text, inline=False)
|
| 48 |
embed.add_field(name="New Balance", value=f"${self.balance:.2f}", inline=False)
|
| 49 |
|
| 50 |
+
# Disable the button after spin to prevent multiple spins
|
| 51 |
self.disable_all_items()
|
| 52 |
|
| 53 |
+
await interaction.edit_original_response(embed=embed, view=self)
|
| 54 |
|
| 55 |
class RouletteBotClient(discord.Client):
|
| 56 |
def __init__(self):
|
|
|
|
| 59 |
super().__init__(intents=intents)
|
| 60 |
self.tree = app_commands.CommandTree(self)
|
| 61 |
|
| 62 |
+
async def setup_hook(self):
|
| 63 |
await self.tree.sync()
|
| 64 |
+
|
| 65 |
+
async def on_ready(self):
|
| 66 |
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
| 67 |
print('------')
|
| 68 |
|
| 69 |
client = RouletteBotClient()
|
| 70 |
|
| 71 |
+
@client.tree.command(name="roulette", description="Play a game of roulette!")
|
| 72 |
@app_commands.describe(
|
| 73 |
bet="Amount you want to bet",
|
| 74 |
choice="Choose red, green, or black"
|
|
|
|
| 78 |
choice = choice.lower()
|
| 79 |
|
| 80 |
if choice not in ROULETTE_COLORS:
|
| 81 |
+
await interaction.response.send_message("choose **red**, **green**, or **black**.", ephemeral=True)
|
| 82 |
return
|
| 83 |
|
| 84 |
if bet <= 0:
|
|
|
|
| 88 |
balance = user_cash.get(user_id, 1000.0) # Default starting balance
|
| 89 |
|
| 90 |
if bet > balance:
|
| 91 |
+
await interaction.response.send_message(f"You don't have MONEY. Your current balance is ${balance:.2f}.", ephemeral=True)
|
| 92 |
return
|
| 93 |
|
| 94 |
# Deduct the bet initially
|
|
|
|
| 99 |
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
|
| 100 |
|
| 101 |
view = RouletteView(user_id, bet, choice, balance)
|
| 102 |
+
await interaction.response.send_message(embed=embed, view=view)
|