[英]why does my if statement not work in python?
这是电报机器人的简单代码。 我有一个列表,当用户键入“ m”时,其名称将添加到列表中,并且机器人将发布该列表。当用户键入“ n”时,将从列表中删除该名称并发布该列表。 list等于2,则漫游器应说“完成:并且不接收其他金额”当列表数等于0时,漫游器应说“无人”并发布列表。
但是当我运行这段代码时,当list等于0时,什么也没发生!
# -*- 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("898399795:AAEI-HlZ2EIMgB-DRAhyqqm6k4NeSoeohhM")
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()
我看你的情况不对
if len(listt) == 2
应该
if len(listt) == 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.