有人知道如何创建一个可以将用户消息存储在变量中的事件吗



例如,我想检查用户消息是否等于"hello"。以下是我迄今为止设法编写的代码:

@client.event           
async def on_message(message):
messageContent = message.content
if len(messageContent) > 0:
if messageContent == "hello":
await message.channel.send('Do not say that!')
else:
return

您的代码应该是正确的,我只是做了一些调整,但这是否回答了您的问题,或者您还在寻找什么?

@client.event
async def on_message(message):

# Storing the message in a variable and transforming the string into all lowercase #

msg = message.content.lower()

# Checking if the message is equal to hello
if str(msg) == "hello":
await message.channel.send('You are not allowed to say that!')
else:
return

最新更新