Reputation:
I create a telegram bot whit python-telegram-bot.I want to post the message to the group after sending messages to the group,and the bot check the message, and if the word in the mlist is in messages, the bot will delete the message, but if the messages are in Persian, the bot will not delete it, but if the message In Latin, the bot will delete it.Look at the messages in the mlist, when the bot sends Hello to the group, it delete it, but when the سلام sends to the group it does not delete the bot.
# -*- coding: cp1256 -*-
#!/usr/bin/python
import os, sys
from telegram.ext import Filters
from telegram.ext import Updater, MessageHandler
import re
def delete_method(bot, update):
if not update.message.text:
print("it does not contain text")
return
mlist=['Hello', 'سلام']
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 messages while sending the Persian messages in the mlist to the group, but it will not do this, but if the messages in the mlist are in Latin and will be sent to the group, messages will be deleted. . There is no error at all
Upvotes: 0
Views: 372
Reputation: 590
First you need to debug your program to see if it reaches inside the if clause or not.
and also change the first line to:
# -*- coding: utf-8 -*-
see if it works..
Upvotes: 0