I built a telegram bot with Python-Telegram-Bot.I added the bot to a group and got the bot in the admin group.I have defined a list(mlist) for the bot and put it in a list of words.The bot should check the messages the users send to the group.And if users send a message to the group in which the words defined in the list(mlist) are there, the bot must delete it(delete message).
# -*- coding: utf-8 -*-
import os, sys
from telegram.ext import Updater, MessageHandler, Fliters
import re
def delete_method(bot, update):
if not update.message.text:
print("it does not contain text")
return
mlist=['سلام', 'شادي']
for i in mlist:
if re.search(i, update.message.text):
bot.delete_message(chat_id=update.message.chat_id, message_id=update.message.message_id)
def main():
updater = Updater(token='TOKEN')
dispatcher = updater.dispatcher
dispatcher.add_handler(MessageHandler(Filters.all, delete_method))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
# for exit
# updater.idle()
(The bot should delete the messages that are sent to the group and contain the list(mlist) words) ;But the bot does not work, and does not give error.