I have written a function named guesstall
which is a number guessing game. I am trying to convert the code into a discord bot command. Discord users should be able to initiate the game by using -guesstall
.
I am very new to Python, just started with discord.py today. Any help would be appreciated.
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的重写版本,它会让它更容易
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.