dimanche 21 juillet 2019

one of my if statement do not work in python

this is a simple code for telegram bot. I have a list, When the user types "m", its name is added to the list and the robot publishes the list, When the user types "n", the name is deleted from the list and publishes the list, When the number of the list is equal to 2, the bot should say "Done: and not receive another amount When the number of the list is equal to 0 The robot should say "No one" and publishes the list.

but when I run this code,when list equals to 0 nothing happens!

# -*- coding:utf-8 -*-
#coding=UTF-8

from telegram.ext import Updater , CommandHandler , Filters , 
CommandHandler , MessageHandler
from telegram import MessageEntity
from telegram import ParseMode , InputTextMessageContent

updater = Updater("BOT TOKEN")

listt = []


def msg_filter(bot , update):
    wordsp = ['m']
    wordsn = ['n']



    if any (i in update.message.text for i in wordsp) and " 
    {}".format(update.message.from_user.first_name) not in listt:

    listt.append("{}".format(update.message.from_user.first_name))
    bot.send_message(chat_id = update.message.chat_id , text = 
    "\n".join(listt))
    bot.send_message(chat_id = update.message.chat_id , text = len(listt))

       if len(listt)==2:
           bot.send_message(chat_id = update.message.chat_id , text = 
           "Done")

    if any (i in update.message.text for i in wordsn) and " 
    {}".format(update.message.from_user.first_name)  in listt:


    listt.remove("{}".format(update.message.from_user.first_name))
    bot.send_message(chat_id = update.message.chat_id , text = 
    "\n".join(listt))

    bot.send_message(chat_id = update.message.chat_id , text = len(listt))

       if len(listt)==0:
       bot.send_message(chat_id = update.message.chat_id , text = 
       "nobody")



print(listt)
print(len(listt))

updater.dispatcher.add_handler(MessageHandler(Filters.text , msg_filter ))
updater.start_polling()

Aucun commentaire:

Enregistrer un commentaire