![](/img/trans.png)
[英]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
[英]The telegram bot does not delete stickers from the group
我使用Python-Telegram-Bot框架和Re Module創建了一個電報機器人。 僵屍程序應刪除成員發送給組的標簽,即當單詞start
發送給組時,它將刪除在組start
之后發送的僵屍程序標簽。
我的代碼:
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()
但是,該漫游器無法正常工作,也就是說,在將發送start
字樣發送給該組之后,它不會刪除發送給該組的標簽。
代碼沒有任何錯誤,該組是一個超級組,該機器人是admin,可以訪問消息!
您認為是什么問題???
if re.match(i, update, message.text):
這行是問題。 您正在update
對象中搜索i
(其值為/start
)。 我不明白為什么這應該工作。
您需要檢查當前消息是否為貼紙。 如果消息是貼紙,則update.effective_message.sticker
將返回一個值。 否則它將返回None
。 所以我猜你可以檢查貼紙-我沒有測試:
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.