不知道如何继续这个不协调的python代码

2024-06-30 07:46:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经编写了一个名为guesstall的函数,这是一个数字猜测游戏。我正在尝试将代码转换为discord bot命令。Discord用户应该能够使用-guesstall启动游戏

我对Python非常陌生,今天刚开始使用discord.py。任何帮助都将不胜感激

async def guesstall(message):
    n = int(random.randint(1, 50))

    gjett = 5

    while gjett > 0:
      await message.channel.send("Guess a number")
      t = message.content()
      time.sleep(1)
      if t == n:
       await message.channel.send("Your guess was correct")
       break

      elif t < n:
        await message.channel.send("The number is higher than your guess")
        gjett -= 1
        await message.channel.send("you have", str(gjett), "guesses left.")
        await message.channel.send("")

      elif t > n:
        await message.channel.send("The number is smaller than your number")
        gjett -= 1
        await message.channel.send("You have", str(gjett), "guesses left.")
        await message.channel.send("")

      if gjett == 0:
        await message.channel.send("You failed")
        await message.channel.send("The number was", str(n))

  if message.content.startswith("-guesstall"):
    await guesstall(message)

Tags: thesend游戏numbermessageifchannelcontent