>>> message = "I would like to go home"
>>> words = ["home", ...]
>>> message in words
False
You're comparing the WHOLE message content to the list, if the list was something like this ["I would like to go home", ...]
the result would be True
, but it's not, for that you can use the any
function
>>> message = "I would like to go home"
>>> words = ["home", ...]
>>> any(word in message for word in words)
True
>>> message = "Something else"
>>> any(word in message for word in words)
False
It's the same as
>>> def words_in_message(content: str, words: list[str]) -> bool:
... for word in words:
... if word in content:
... return True
... return False
>>>
>>> message = "I would like to go home"
>>> words = ["home", ...]
>>> words_in_message(message, words)
True
>>> message = "Something else"
>>> words_in_message(message, words)
False
Your code should look like this
world_list = ['home', 'house', 'maison']
@client.listen('on_message')
async def on_message(message):
if any(word in message.content for word in words):
await message.channel.send("i'm coming home")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…