一遍又一遍地编辑相同的消息

时间:2020-11-10 17:43:54

标签: python python-3.x discord.py discord.py-rewrite

(discord.py 1.5.0)我试图为discord.py做一个赌博游戏,并试图增加一遍又一遍编辑同一条消息的概念。从结果来看,编辑在第一次编辑后就停止了。没有错误。这是完整的命令代码。

  cooldown_num = 0
  @game_eco.command(description="Pick a color where you think the ball would drop!", aliases=['balldrop'])
  @cooldown(1, cooldown_num, BucketType.user)
  async def drop_the_ball(self, ctx, bet: int=None, color=None):
    chance = random.randint(1, 4)

    if bet is None and color is None:
      await ctx.send("**Colors pickable - `red`, `blue`, `green`, and `yellow`**\nDo `gamble drop_the_ball <bet> <color>` to start playing!")

    else:
      bal = await update_eco(ctx.author)
      if bet > bal[0]:
        await ctx.send("You do not have enough shards in your purse in order to bet that much amount loll <:kekw:773125072637788160>")
        return
      
      if bet < 0:
        await ctx.send("<a:weeeee:771309755427061770> Number must be positive kiddo <a:weeeee:771309755427061770>")
        return

      cooldown_num = 300
      await ctx.send("**THE BALL HAS DROPPED!**")
      msg= await ctx.send("    :volleyball:\n\n\n:blue_square::red_square:\n:green_square::yellow_square:")
      await asyncio.sleep(.5)
      await msg.edit(content='    :volleyball:\n\n:blue_square::red_square:\n:green_square::yellow_square:')

      messages=[
      "**YOU WON!** You get __150%__ of the Nitro Shards <a:boost_evolve:769448461824163870> you betted!", 
      f'**YOU LOST!** your {bet} shards... gone! try again in 5 minutes :)'
      ]
      choices1 = ['‏ ‏‏‎ ‎‎    ‎ :volleyball:\n:blue_square::red_square:\n:green_square::yellow_square:',
                  ':volleyball:\n:blue_square::red_square:\n:green_square::yellow_square:'
                  ]

      async def volleyball_fall(side):
        if side == 'left':
          await msg.edit(content=choices1[1])
          await asyncio.sleep(.5)
          await msg.edit(content=":volleyball::red_square:\n::green_square::yellow_square:")
          await asyncio.sleep(1.5)

        elif side == 'right':
          await msg.edit(content=choices1[0])
          await asyncio.sleep(.5)
          await msg.edit(content=':blue_square::volleyball:\n:green_square::yellow_square:')
          await asyncio.sleep(1.5)

      async def lose_func(chance, color):
        leftorright = random.choice(["left", "right"])
    
        if chance == 1 and color in ("Blue", "blue"):
          await volleyball_fall(leftorright)
          if leftorright == "left":
            await msg.edit(":blue_square::red_square:\n:volleyball::yellow_square:")
            await ctx.send(messages[1])
          else:
            await ctx.send(messages[1])
        elif chance == 2 and color in ("Red", "red"):
          await volleyball_fall(leftorright)
          if leftorright == "right":
            await msg.edit(":blue_square::red_square:\n:green_square::volleyball:")
            await ctx.send(messages[1])
          else:
            await ctx.send(messages[1])
        elif chance == 3 and color in ("Green", "green"):
          await volleyball_fall(leftorright)
          if leftorright == "left":
            await ctx.send(messages[1])
          else:
            await ctx.send(messages[1])
        elif chance == 4 and color in ("Yellow", "yellow"):
          await volleyball_fall(leftorright)
          if leftorright == "right":
            await ctx.send(messages[1])
          else:
            await ctx.send(messages[1])

        users = await get_bank_data()
        users[str(ctx.author.id)]["purse"] -= bet

        with open("databases/economy.json", "w") as f:
          json.dump(users, f)


      if color == 'blue' or color == 'Blue':
        if chance == 1:
          await volleyball_fall("left")

          users = await get_bank_data()
          users[str(ctx.author.id)]["purse"] += bet * 1.5

          with open("databases/economy.json", "w") as f:
            json.dump(users, f)

          await ctx.send(messages[0])

        else:
          await lose_func(chance, color)
      elif color == 'red' or color == 'Red':
        if chance == 2:
          volleyball_fall("right")

          users = await get_bank_data()

          users[str(ctx.author.id)]["purse"] += bet * 1.5
          with open("databases/economy.json", "w") as f:
            json.dump(users, f)

          await ctx.send(messages[0])

          return

        else:
          await lose_func(chance, color)

      elif color == 'green' or color == 'Green':
        if chance == 3:
          await volleyball_fall("left")
          msg=msg.edit(content=':blue_square::red_square:\n:volleyball::yellow_square:')

          users = await get_bank_data()

          users[str(ctx.author.id)]["purse"] += bet * 1.5

          with open("databases/economy.json", "w") as f:
            json.dump(users, f)

          await ctx.send(messages[0])
          return

        else:
          await lose_func(chance, color)

      elif color == 'yellow' or color == 'Yellow':
        if chance == 4:
          await volleyball_fall("right")
          msg=msg.edit(content=':blue_square::red_square:\n:green_square::volleyball:')

          users = await get_bank_data()

          users[str(ctx.author.id)]["purse"] += bet * 1.5

          with open("databases/economy.json", "w") as f:
            json.dump(users, f)

          await ctx.send(messages[0])
          return

        else:
          await lose_func(chance, color)

我做的这个“赌博游戏”是关于猜测球将落在什么颜色的面上。 左上(蓝色),右上(红色),左下(绿色)或右下(黄色)。

0 个答案:

没有答案