The embed doesnt send anymore for some reason.
Im going to just send the code for my blackjack. I hope you’re able to fix this
class BlackjackView(View):
def __init__(self, ctx, bot, accounts, author_id, bet, message, dealer_hand, dealer_total, player_hand, player_total):
super().__init__()
self.ctx = ctx
self.bot = bot
self.accounts = accounts
self.author_id = author_id
self.bet = bet
self.message = message
self.dealer_hand = dealer_hand
self.dealer_total = dealer_total
self.player_hand = player_hand
self.player_total = player_total
@discord.ui.button(label="Hit", style=discord.ButtonStyle.green)
async def hit_button_callback(self, button, interaction):
if interaction.user != self.ctx.author:
return
# Hit logic
self.player_hand.append(draw_card())
self.player_total = calculate_total(self.player_hand)
embed = self.message.embeds[0] # Assuming embed is the first one
embed.set_field_at(0, name=f"Your Cards: {self.player_total}", value=format_hand(self.player_hand), inline=False)
await self.message.edit(embed=embed)
if self.player_total > 21:
await handle_loss(self.ctx, self.accounts, self.author_id, self.bet, self.message, self.dealer_hand, self.dealer_total, self.player_total, self.player_hand)
self.stop()
@discord.ui.button(label="Stand", style=discord.ButtonStyle.red)
async def stand_button_callback(self, button, interaction):
if interaction.user != self.ctx.author:
return
# Stand logic
while self.dealer_total < 17:
self.dealer_hand.append(draw_card())
self.dealer_total = calculate_total(self.dealer_hand)
embed = self.message.embeds[0] # Assuming embed is the first one
embed.set_field_at(1, name=f"Dealer's Cards: {self.dealer_total}", value=format_hand(self.dealer_hand), inline=False)
await self.message.edit(embed=embed)
if self.dealer_total >= 17:
if self.dealer_total > 21 or self.player_total > self.dealer_total:
await handle_win(self.ctx, self.accounts, self.author_id, self.bet, self.message, self.dealer_hand, self.dealer_total, self.player_total, self.player_hand)
elif self.player_total > 21 or self.player_total < self.dealer_total:
await handle_loss(self.ctx, self.accounts, self.author_id, self.bet, self.message, self.dealer_hand, self.dealer_total, self.player_total, self.player_hand)
else:
await handle_tie(self.ctx, self.accounts, self.author_id, self.bet, self.message, self.dealer_hand, self.dealer_total, self.player_total, self.player_hand)
self.stop()
# Define your bot instanc
@bot.command(name="blackjack", aliases=["bj"])
async def blackjack(ctx, bet: int):
author_id = str(ctx.author.id)
player_hand = [draw_card(), draw_card()]
dealer_hand = [draw_card(), draw_card()]
player_total = calculate_total(player_hand)
dealer_total = calculate_total(dealer_hand[1:])
embed = discord.Embed(title="", color=0x232428)
embed.add_field(name=f"Your Cards: {player_total}", value=format_hand(player_hand), inline=False)
embed.add_field(name=f"Dealer's Cards: {dealer_total}", value=f"{format_hand(dealer_hand[1:])} ??? ", inline=False)
embed.add_field(name="Result", value="In progress", inline=False)
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
embed.set_thumbnail(url="https://i.imgur.com/JBPnaZz.png")
view = BlackjackView(ctx, bot, accounts, author_id, bet, message, dealer_hand, dealer_total, player_hand, player_total)
await message.edit(view=view)
def draw_card():
return random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10])
def calculate_total(hand):
total = sum(hand)
num_aces = hand.count(1)
while total <= 11 and num_aces > 0:
total += 10
num_aces -= 1
return total
def format_hand(hand):
card_names = {1: 'A', 10: 'J', 11: 'Q', 12: 'K'}
return ", ".join(str(card_names.get(card, card)) for card in hand)
async def handle_win(ctx, bet, message, dealer_hand, dealer_total, player_total, player_hand):
embed = discord.Embed(title="", color=0x232428)
embed.add_field(name=f"Your Cards: {player_total}", value=f"{format_hand(player_hand)}", inline=False)
embed.add_field(name=f"Dealer's Cards: {dealer_total}", value=format_hand(dealer_hand), inline=False)
embed.add_field(name="Result", value=f"You won! Your new balance is: **{bet * 2}**", inline=False)
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
embed.set_thumbnail(url="https://i.imgur.com/JBPnaZz.png")
await message.edit(embed=embed)
async def handle_loss(ctx, bet, message, dealer_hand, dealer_total, player_total, player_hand):
embed = discord.Embed(title="", color=0x232428)
embed.add_field(name=f"Your Cards: {player_total}", value=f"{format_hand(player_hand)}", inline=False)
embed.add_field(name=f"Dealer's Cards: {dealer_total}", value=format_hand(dealer_hand), inline=False)
embed.add_field(name="Result", value=f"You lost. Your new balance is: **0**", inline=False)
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
embed.set_thumbnail(url="https://i.imgur.com/JBPnaZz.png")
await message.edit(embed=embed)
async def handle_tie(ctx, bet, message, dealer_hand, dealer_total, player_total, player_hand):
embed = discord.Embed(title="", color=0x232428)
embed.add_field(name=f"Your Cards: {player_total}", value=f"{format_hand(player_hand)}", inline=False)
embed.add_field(name=f"Dealer's Cards: {dealer_total}", value=format_hand(dealer_hand), inline=False)
embed.add_field(name="Result", value=f"The hand is a push. Your new balance is: **{bet}**", inline=False)
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
embed.set_thumbnail(url="https://i.imgur.com/JBPnaZz.png")
await message.edit(embed=embed)