File size: 2,707 Bytes
907240b
 
 
 
ca6040a
907240b
ca6040a
f338b32
 
 
 
 
 
ca6040a
907240b
ca6040a
907240b
ca6040a
907240b
ca6040a
907240b
ca6040a
 
907240b
f338b32
ca6040a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f338b32
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import discord
from discord import app_commands
import random

from cash import user_cash

@app_commands.command(name="roulette", description="Play roulette and bet")
async def roulette(interaction: discord.Interaction, bet: int):
    await play_roulette(interaction, bet)

async def play_roulette(interaction: discord.Interaction, bet: int):
    user_id = interaction.user.id
    balance = user_cash.get(user_id, 0)
    
    if bet <= 0:
        await interaction.response.send_message("Bet higher than 0, please.")
        return
    
    if bet > balance:
        await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")
        return
    
    embed = discord.Embed(title="Roulette Game", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x3498db)
    embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
    
    spin_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin the Roulette", custom_id="spin_roulette")
    
    async def spin_roulette_callback(interaction: discord.Interaction):
        nonlocal balance
        result = random.choice(["win", "lose"])
        
        if result == "win":
            winnings = bet * 2  # Assuming a simple win condition for demonstration
            balance += winnings
            result_text = f"You won ${winnings:.2f}!"
        else:
            balance -= bet
            result_text = f"You lost ${bet:.2f}."
        
        user_cash[user_id] = balance
        
        embed.clear_fields()
        embed.add_field(name="Result", value=result_text, inline=False)
        embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
        
        spin_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin Again", custom_id="spin_again")
        
        async def spin_again_callback(interaction: discord.Interaction):
            if interaction.user.id == user_id:
                await play_roulette(interaction, bet)
            else:
                await interaction.response.send_message("You can't spin this.", ephemeral=True)
        
        spin_again_button.callback = spin_again_callback
        
        new_view = discord.ui.View()
        new_view.add_item(spin_again_button)
        
        await interaction.response.edit_message(embed=embed, view=new_view)
    
    spin_button.callback = spin_roulette_callback
    
    view = discord.ui.View()
    view.add_item(spin_button)
    
    if interaction.response.is_done():
        await interaction.followup.send(embed=embed, view=view)
    else:
        await interaction.response.send_message(embed=embed, view=view)