简体   繁体   中英

When the command / start is sent to the bot, the bot should delete the stickers sent to the group; but the bot does not work

I am built a telegram bot with the Python-Telegram-Bot framework.I added it to a group and admin the bot in the group.

bot codes:

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

updater = Updater(token='TOKEN')
dispatcher = updater.dispatcher

def sticker_method(bot, update):
    update.message.delete()

def sticker_delete():
    dispatcher.add_handler(MessageHandler(Filters.sticker, sticker_method))
    updater.start_polling() 
    updater.idle()

def sticker_undelete():
    dispatcher.remove_handler(MessageHandler(Filters.sticker, sticker_method))

start_command = CommandHandler('start', sticker_delete)
dispatcher.add_handler(start_command)

notdelete_command = CommandHandler('notdelete', sticker_undelete)
dispatcher.add_handler(notdelete_command)

updater.start_polling() 
updater.idle()

After the group creator sends the bot command /start , the bot will delete the stickers that the group members send to the group.

And also, when the group creator command /notdelete send it to the bot, the bot should not delete the stickers that members send to the group.

But the bot does not work; when the group creator sends the group command /start to the bot, it will not delete the bot stickers that are sent to the group.

What do you think the problem is that the bot does not work ???

The codes do not give any error, but as I said, the bot does not work.

First, make sure it's supergroup , not normal group

Your bot need Delete Message permission, and Privacy Mode should be disabled.

Bots can't get message list, they can only receive that when someone send it, so you need to log Enable/Disable state to your own database, and delete Sticker when received new message.

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