import discord from discord import app_commands import random # Simple in-memory storage for user balances user_cash = {} # Colors for roulette ROULETTE_COLORS = ["red", "green", "black"] class RouletteView(discord.ui.View): def __init__(self, user_id, bet, choice, balance): super().__init__(timeout=None) self.user_id = user_id self.bet = bet self.choice = choice self.balance = balance @discord.ui.button(label="Spin the Roulette", style=discord.ButtonStyle.primary, custom_id="spin_button") async def spin_button_callback(self, interaction: discord.Interaction, button: discord.ui.Button): if interaction.user.id != self.user_id: await interaction.response.send_message("non.", ephemeral=True) return result = random.choices(ROULETTE_COLORS, weights=[18, 1, 18], k=1)[0] if result == self.choice: if result == "green": winnings = self.bet * 14 # Green typically has higher payout self.balance += winnings result_text = f"🎉 You won ${winnings:.2f}! The ball landed on **GREEN**." else: winnings = self.bet * 2 self.balance += winnings result_text = f"🎉 You won ${winnings:.2f}! The ball landed on **{result.upper()}**." else: self.balance -= self.bet result_text = f"😞 You lost ${self.bet:.2f}. The ball landed on **{result.upper()}**." # Update user balance user_cash[self.user_id] = self.balance embed = discord.Embed(title="🎰 Roulette Result", color=0xFFD700) embed.add_field(name="Result", value=result_text, inline=False) embed.add_field(name="New Balance", value=f"${self.balance:.2f}", inline=False) # Disable the button after spin self.disable_all_items() await interaction.response.edit_message(embed=embed, view=self) class RouletteBotClient(discord.Client): def __init__(self): intents = discord.Intents.default() intents.message_content = True super().__init__(intents=intents) self.tree = app_commands.CommandTree(self) async def on_ready(self): await self.tree.sync() print(f'Logged in as {self.user} (ID: {self.user.id})') print('------') client = RouletteBotClient() @client.tree.command(name="roulette", description="roulette simple as that") @app_commands.describe( bet="Amount you want to bet", choice="Choose red, green, or black" ) async def roulette(interaction: discord.Interaction, bet: float, choice: str): user_id = interaction.user.id choice = choice.lower() if choice not in ROULETTE_COLORS: await interaction.response.send_message("Invalid choice! Please choose **red**, **green**, or **black**.", ephemeral=True) return if bet <= 0: await interaction.response.send_message("Your bet must be higher than $0.", ephemeral=True) return balance = user_cash.get(user_id, 1000.0) # Default starting balance if bet > balance: await interaction.response.send_message(f"you dont got money this is how much you got ${balance:.2f}.", ephemeral=True) return # Deduct the bet initially balance -= bet user_cash[user_id] = balance embed = discord.Embed(title="🎲 Roulette Started", description=f"{interaction.user.mention} has placed a bet of ${bet:.2f} on **{choice.upper()}**.", color=0x787878) embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False) view = RouletteView(user_id, bet, choice, balance) view.message = await interaction.response.send_message(embed=embed, view=view)