简体   繁体   English

电报漫游器不会从组中删除贴纸

[英]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. 我使用Python-Telegram-Bot框架和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 . 僵尸程序应删除成员发送给组的标签,即当单词start发送给组时,它将删除在组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. 但是,该漫游器无法正常工作,也就是说,在将发送start字样发送给该组之后,它不会删除发送给该组的标签。

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! 代码没有任何错误,该组是一个超级组,该机器人是admin,可以访问消息!

What do you think is the problem ??? 您认为是什么问题???

This line here if re.match(i, update, message.text): is the problem. if re.match(i, update, message.text):这行是问题。 You are searching for i (which has the value /start ) in the update object. 您正在update对象中搜索i (其值为/start )。 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. 如果消息是贴纸,则update.effective_message.sticker将返回一个值。 Otherwise it will return None . 否则它将返回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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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