Inlowik
Inlowik

Reputation: 49

One of my embeds aren't working, but my other 2 with the nearly same code, are

I have 3 embeds. 2 of them show the correct embeds, but one of them just shows a blank embed. the codes are nearly the same, so I don't know whats wrong. Here is my code for my function:

My code:

@client.command()
async def slots(ctx, amount = None):
  await open_account(ctx.author)
    
  if amount == None:
    await ctx.send("How ya gonna slots 0 coins, dum dum")
    return
    
  bal = await update_bank(ctx.author)
    
  amount = int(amount)
  if amount>(bal[0]+1):
    await ctx.send("You don't even have that many coins, idiot")
    return
  if amount<0:
    await ctx.send("You wanna lose money by gambling negative coins?")
    return
    
  final = []
  for i in range(3):
    a = random.choice([":egg:", ":baby_chick:", ":hatching_chick:",":hatched_chick:",':poultry_leg:',':chicken:'])
    final.append(a)
    
  em = Embed(title = f"{ctx.author}s Slots Game", color = discord.Color.lighter_grey())
  em.add_field(name = final, value = f"\n{ctx.author}s Slots Game", inline = False)
  msg = await ctx.send(embed = em)
    
  if final[0] == final[1] or final[0] == final[2] or final[1] == final[2]:
    await update_bank(ctx.author, 2*amount)
    em_new = Embed(title = f"{ctx.author}s Slots Game", color = discord.Color.green())
    em_new.add_field(name = final, value = f"\n{ctx.author}s Slots Game", inline = False)
    em_new.add_field(name = "Win!", value = f"You won {2*amount} coins!")
    sleep(1)
    await msg.edit(embed=em_new)
    if final[0] == final[1] == final[2]:
      await update_bank(ctx.author, 3*amount)
      em_new = Embed(title = f"{ctx.author}s Slots Game", color = discord.Color.green())
      em_new.add_field(name = final, value = f"\n{ctx.author}s Slots Game", inline = False)
      em_new.add_field(name = "Win!", value = f"You won {3*amount} coins!")
      sleep(1)
      await msg.edit(embed=em_new)
  else:
    await update_bank(ctx.author, -1*amount)
    em_new = Embed(title = f"{ctx.author}s Slots Game", color = discord.Color.red())
    em_new.add_field(name = final, value = f"\n{ctx.author}s Slots Game", inline = False)
    em_new = discord.Embed(name = "Loss!", value = f"You lost {-1*amount} coins.")
    sleep(1)
    await msg.edit(embed=em_new)

the first 2 if statement embed things are working, they edit and show what they're supposed to show. But the else statement embed just shows a blank embed. can someone pls help me

Upvotes: 0

Views: 58

Answers (1)

chluebi
chluebi

Reputation: 1829

In this line of code

em_new = discord.Embed(name = "Loss!", value = f"You lost {-1*amount} coins.")

You are calling an embed via discord.Embed while in all other cases you are using Embed by itself. Considering that all embeds except for this work I assume your imports look similar to the following:

from discord import Embed

With this import structure you do not need to specify discord.Embed So change the line of code to the following:

em_new = Embed(name = "Loss!", value = f"You lost {-1*amount} coins.")

Additionally I should remark that you should probably replace time.sleep with its asyncio equivalent. You can find more info about that here.

Upvotes: 3

Related Questions