我正在尝试做一个命令,激活一个随机数猜谜游戏。很明显,我被困在前几行了。我写了我认为可行的东西,但它可能是明显错误的。我希望它将discord服务器上的消息更改为int,这样它就可以在if语句中工作。在
这是我第一次做机器人不和.py,所以我遇到了很多障碍。我不能完全确定错误在告诉我什么,所以我无法尝试任何修复。代码如下:
async def numgame(context):
number = random.randint(1,100)
for guess in range(0,5):
await context.send('Pick a number between 1 and 100')
Message = await client.wait_for('message')
Message = int(Message)
if Message.cleant_content > number:
await context.send(guess + ' guesses left...')
asyncio.sleep(1)
await context.send('Try going lower')
asyncio.sleep(1)
elif Message.clean_content < number:
await context.send(guess + ' guesses left...')
asyncio.sleep(1)
await context.send('Try going higher')
asyncio.sleep(1)
else:
await context.send('You guessed it! Good job!')
if number != Message:
await context.send('Tough luck!')
每当我在discord服务器中执行命令时,shell都会显示以下错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: int() argument must be a string, a bytes-like object or a number, not 'Message'
我不太清楚它在告诉我什么。如前所述,我希望“Message”是一个整数,但是我得到了错误。但我们会很感激你的帮助! [还是初学者,不要太苛刻:(]
wait_for('message')
返回一个Message
对象,int
还不知道如何处理。您需要将Message.content
转换为int。下面是您的代码以及一些其他更改:相关问题 更多 >
编程相关推荐