简体   繁体   中英

The telegram bot does not delete stickers from the group

I create a telegram bot using the Python-Telegram-Bot framework and the Re Module. The bot should delete the stickers the members send to the group, that is, when the word is start send to the group, it will delete the bot stickers that are sent after the group start .

My code:

from telegram.ext import Updater, MessageHandler, Filters
import re                                                                                                                          


def delete_method(bot, update):
    mlist=['/start']  
    for i in mlist:
        if re.match(i, update, message.text):
            update.message.delete()


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()

But the bot does not work, that is, after sending the word start of the send to the group, it does not delete the stickers that are sent to the group.

The codes do not give any errors.And the group is a super group, and the bot is admin and it has access to messages!

What do you think is the problem ???

This line here if re.match(i, update, message.text): is the problem. You are searching for i (which has the value /start ) in the update object. I don't see why this should work.

You need to check if the current message is a sticker. If the message is a sticker, then update.effective_message.sticker will return a value. Otherwise it will return None . So you could check for a sticker with this i guess - i didn't test it:

from telegram.ext import Updater, MessageHandler, Filters


def delete_sticker(bot, update):
    if update.effective_message.sticker:
        update.message.delete


if __name__ == '__main__':
    updater = Updater(token='TOKEN')
    dispatcher = updater.dispatcher
    dispatcher.add_handler(MessageHandler(Filters.all, delete_sticker))

    updater.start_polling()
    updater.idle()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM