Hello i’m trying to make a custom bot for telegram in Python.
i’m looking to use a world list combined with in message content.
world_list = ['home', 'house', 'maison']
@client.listen('on_message')
async def on_message(message):
if message.content in world_list:
await message.channel.send("i'm coming home")
with this code if a use write
i would like to go home
bot remain silent, it work only if the message is a single world of the list, how i can fix it?
4
Answers
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 beTrue
, but it’s not, for that you can use theany
functionIt’s the same as
Your code should look like this
You must check single words for existence in
world_list
returns
True
orFalse
so use it like this
you are currently checking whether the whole message content is on the list. But you are trying to achieve another thing checking whether any of the list items is in the message content.
try doing it like this,
Just loop through the list;