插槽命令无法正常运行不和谐

时间:2020-10-27 04:39:23

标签: discord.py

我正在执行插槽命令。我使用的是YouTube tutorial,但是在本教程中,他们这样做是为了使当连续出现3时,您得到的钱是两倍而不是三倍。我尝试了几种方法,但没有一种起作用。有一种方法可以正常工作,但是漫游器会连续发送2和3的嵌入。有点难以解释,但这是img。最终我放弃了

这是代码:

    @commands.command()
  @commands.cooldown(1, 30, commands.BucketType.user)
  async def slots(self, ctx, amount=None):
      await open_account(ctx.author)

      if amount == None:
          await ctx.send("Please enter an amount")
          return

      bal = await update_bank(ctx.author)

      amount = int(amount)
      if amount > bal[0]:
          await ctx.send("You don't have that much money!")
          return
      if amount < 0:
          await ctx.send("Amount must be positive")
          return

      final = []
      for i in range(3):
            a = random.choice([":apple:", ":star:", ":full_moon:"])

            final.append(a)

      if final[0] == final[1] or final[0] == final[2] or final[2] == final[1]:
            await update_bank(ctx.author, 2 * amount)
            embed = discord.Embed(title="Result", color=discord.Color.green())
            embed.add_field(name="The result", value=final)
            embed.add_field(
                name="\u200b", value=f"You won {2*amount} coins", inline=False)
            await ctx.send(embed=embed)
      else:
            await update_bank(ctx.author, -1 * amount)
            embed = discord.Embed(title="Result", color=discord.Color.red())
            embed.add_field(name="The result", value=final)
            embed.add_field(
                name="\u200b",
                value=f"You lost {-1*amount} coins",
                inline=False)
            await ctx.send(embed=embed)
      if final[0] == final[1] and final[0] == final[2] and final[1] == final[2]:
                await update_bank(ctx.author, 3 * amount)
                embed = discord.Embed(title="Result", colour=discord.Color.green())
                embed.add_field(name="The result", value=final)
                embed.add_field(
                      name="\u200b",
                      value=
                      f"You won {3*amount} coins. Woah, dude 3 in row? That's sick",
                      inline=False)
                await ctx.send(embed=embed)

我想要它,以便当您连续获得3个机器人时,机器人会将嵌入的3个机器人连续发送出去

2 个答案:

答案 0 :(得分:0)

@client.command(pass_context=True)
async def slots(ctx, amount=None):

    if amount == None:
        await ctx.send("Please enter an amount")
        return

    bal = await update_bank(ctx.author)

    amount = int(amount)
    if amount > bal[0]:
        await ctx.send("You don't have that much money!")
        return
    if amount < 0:
        await ctx.send("Amount must be positive")
        return

    slots = ['bus', 'train', 'horse', 'tiger', 'monkey', 'cow']
    slot1 = slots[random.randint(0, 5)]
    slot2 = slots[random.randint(0, 5)]
    slot3 = slots[random.randint(0, 5)]

    slotOutput = '| :{}: | :{}: | :{}: |\n'.format(slot1, slot2, slot3)

    ok = discord.Embed(title = "Slots Machine", color = discord.Color(0xFFEC))
    ok.add_field(name = "{}\nWon".format(slotOutput), value = f'You won {2*amount} coins')


    won = discord.Embed(title = "Slots Machine", color = discord.Color(0xFFEC))
    won.add_field(name = "{}\nWon".format(slotOutput), value = f'You won {3*amount} coins')
    

    lost = discord.Embed(title = "Slots Machine", color = discord.Color(0xFFEC))
    lost.add_field(name = "{}\nLost".format(slotOutput), value = f'You lost {1*amount} coins')


    if slot1 == slot2 == slot3:
        await update_bank(ctx.author, 3 * amount)
        await ctx.send(embed = won)
        return

    if slot1 == slot2:
        await update_bank(ctx.author, 2 * amount)
        await ctx.send(embed = ok)
        return

    else:
        await update_bank(ctx.author, -1 * amount)
        await ctx.send(embed = lost)
        return

这似乎可行,也许您可​​以更改表情符号和内容

答案 1 :(得分:0)

@client.command(aliases = ["slot"])
@commands.cooldown(1, 60, commands.BucketType.user)
async def slots(ctx,amount = None):
    await open_account(ctx.author)
    if amount == None:
        em11 = discord.Embed(title = f"Please enter the amount as well",color = 
discord.Color.red())
        await ctx.send(embed = em11)
        ctx.command.reset_cooldown(ctx)
        return

    bal = await update_bank(ctx.author)

    amount = int(amount)
    if amount > bal[0]:
        em15 = discord.Embed(title = f"You dont have that much money",color = 
discord.Color.red())
        await ctx.send(embed = em15)
        ctx.command.reset_cooldown(ctx)
        return
    if amount < 100:
        em16 = discord.Embed(title = f"Amount must be greater than 100",color = 
discord.Color.red())
        await ctx.send(embed = em16)
        ctx.command.reset_cooldown(ctx)
        return

    slot = ['<:one:840824304937598976>', '<:two:840824558642003998>', 
'<:three:840824657434378250>', '<:four:840824764539863061>', 
'<:five:840828099170926592>', '<:six:840828181622947841>']

    slot1 = random.choice(slot)
    slot2 = random.choice(slot)
    slot3 = random.choice(slot)
    slotOutput = f'| {slot1} | {slot2} | {slot3} |'.format(slot1, slot2, slot3)

    if slot1 == slot2 == slot3:
        await update_bank(ctx.author,2*amount)
        em18 = discord.Embed(title = "Slots Machine",color = discord.Color.green())
        em18.add_field(name = slotOutput.format(slotOutput), value = f"You won 
{2*amount} coins!")
        await ctx.send(embed = em18)
        return

elif slot1 == slot2 or slot1 == slot3 or slot2 == slot3:
    await update_bank(ctx.author,amount)
    em17 = discord.Embed(title = "Slots Machine",color = discord.Color.green())
    em17.add_field(name = slotOutput.format(slotOutput), value = f"You won {amount} coins!")
    await ctx.send(embed = em17)
    return

    else:
        await update_bank(ctx.author,-1*amount)
        em19 = discord.Embed(title = "Slots Machine",color = discord.Color.red())
        em19.add_field(name = slotOutput.format(slotOutput), value = f"You lost 
{amount} coins!")
        await ctx.send(embed = em19)
        return