我正在努力使这段代码更加简单,但是Python非常区分大小写。是否有办法将此代码清理干净???
@client.event
async def on_message(msg):
if 'Marcelo' in msg.content:
print('Keyword found in message')
await msg.channel.send("oh this shit again!")
if 'marcelo' in msg.content:
print('Keyword found in message')
await msg.channel.send("oh this shit again!")
if 'MARCELO' in msg.content:
print('Keyword found in message')
await msg.channel.send("oh this shit again!")
您可以使用
<str>.lower
,如下所示:您可能也不想使用
in
关键字,因为这意味着如果键入“Hey Marcello”,它仍然会输出。考虑到print语句,我不知道这是否是您想要的,但大多数情况下,使用msg.content.lower().startsWith('marcelo')
或msg.content.lower() == 'marcelo'
会更有意义相关问题 更多 >
编程相关推荐