【问题标题】:One of my embeds aren't working, but my other 2 with the nearly same code, are我的一个嵌入不工作,但我的其他 2 个几乎相同的代码,是
【发布时间】:2021-04-13 20:51:44
【问题描述】:

我有 3 个嵌入。其中 2 个显示正确的嵌入,但其中一个仅显示空白嵌入。代码几乎相同,所以我不知道出了什么问题。这是我的函数代码:

我的代码:

@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)

前 2 个 if 语句嵌入工作正常,它们编辑并显示它们应该显示的内容。但是 else 语句嵌入只显示一个空白嵌入。有人可以帮我吗

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    在这行代码中

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

    您正在通过 discord.Embed 调用嵌入,而在所有其他情况下,您正在使用 Embed 本身。 考虑到除了这项工作之外的所有嵌入,我假设您的导入类似于以下内容:

    from discord import Embed
    

    使用此导入结构,您无需指定discord.Embed 所以将这行代码改成如下:

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

    此外,我应该指出,您可能应该将 time.sleep 替换为其 asyncio 等效项。您可以找到有关 here 的更多信息。

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      • 2014-05-08
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      • 2022-12-29
      相关资源
      最近更新 更多