我已经编写了一个名为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)
您应该使用discord.py的重写版本,这将使它更容易
相关问题 更多 >
编程相关推荐