这是我下面的代码。假设数字是 50,我如何让机器人说他们猜得更低(49 或以下)或他们猜得更高(51 及以上)谢谢!
async def on_message(message):
if message.content.startswith(">numbergame"):
channel = message.channel
await channel.send("Guess the number from 0-100 by writing the number in this channel!")
number1 = random.randint(1,100)
print(number1)
number2 = str(number1)
def check(m):
return m.content == number2 and m.channel == channel
msg = await bot.wait_for('message', check=check)
await channel.send(f"Correct answer! {message.author.mention}" .format(msg))
else:
await bot.process_commands(message)```
答案 0 :(得分:1)
这是您的代码,但下次请提出真正的问题。这是一个社区网站,我们正在为所有成员提问或回答问题。
import asyncio
async def on_message(message):
if message.content.startswith(">numbergame"):
channel = message.channel
await channel.send("Guess the number from 0-100 by writing the number in this channel!")
number = random.randint(1,100)
def check(m):
return m.content.isdigit() and m.channel == channel and m.author == message.author
while True:
try:
msg = await bot.wait_for('message', timeout=30.0, check=check)
except asyncio.TimeoutError:
return await channel.send("You are late to guess")
guess = int(msg.content)
if guess == number:
return await channel.send(f"Correct answer! {message.author.mention}")
elif guess > number:
await channel.send("You guess was to high.")
elif guess < number:
await channel.send("Your guess was to low")
else:
await bot.process_commands(message)