【发布时间】:2020-12-29 02:10:16
【问题描述】:
我一直在尝试制作一个不和谐的机器人,它会在发送!play 消息时开始游戏。在游戏中,有一个变量的值是随机选择的,如果您预测正确的数字(1 到 10 之间),则将发送"You win" 消息,如果大于或小于则将相应地发送消息。我知道我搞砸了,因为我是第一次使用 discord.py。
我的代码:
if message.content.startswith("!play"):
await message.channel.send("Choose a number between 1-10. Enter numerical values only.")
num = random.randint(1,10)
try:
if message.content.startswith(str(num)):
await message.channel.send("You won.")
elif int(message.content) > num:
await message.channel.send("Go a bit lower.")
elif int(message.content) < num:
await message.channel.send("Go a bit up.")
except Exception as e:
await message.channel.send("Check inputs.")
请帮忙
【问题讨论】:
标签: python discord.py