This is my code, it works perfectly except for the last if statement.
I want to when the list members become 0 the bot send this message:
"No One"
This code works perfectly when the list reaches 2 bot say: fix.
But when it reaches 0, it doesn’t say anything!
from telegram.ext import Updater , CommandHandler , Filters ,
CommandHandler , MessageHandler
from telegram import MessageEntity
from telegram import ParseMode , InputTextMessageContent
updater = Updater("989165404:AAF8DEjyunwrb88-1G8w62cGItzXj1J618g")
list = []
wordsm=["m"]
wordsn=["n"]
def msg_filter(bot , update):
if any (i in update.message.text for i in wordsm):
list.append("{}".format(update.message.from_user.first_name))
bot.send_message(chat_id = update.message.chat_id , text =
"n".join(list))
if len(list)==2:
bot.send_message(chat_id = update.message.chat_id , text = "FiX!")
if any (j in update.message.text for j in wordsn):
list.remove("{}".format(update.message.from_user.first_name))
bot.send_message(chat_id = update.message.chat_id , text =
"n".join(list))
if len(list)==0:
bot.send_message(chat_id = update.message.chat_id , text = "No
One")
print(list)
print(len(list))
updater.dispatcher.add_handler(MessageHandler(Filters.text
,msg_filter ))
updater.start_polling()
2
Answers
Please check the indentation. I think you have put the “if len(list)==0:” inside “if len(list)==2:”
Maybe I am not looking at this right, but it looks like your
is nested inside your
Both conditions will never both be true simultaneously, so it never enters that condition.
Maybe it should instead be: