电报机器人应删除发送给该组的Sticker,Gif和Voice;但不要删除它们

时间:2017-09-01 09:28:28

标签: python-2.7 python-telegram-bot

我用python-telegram-bot模块构建了一个电报机器人。我将机器人添加到组中并在管理员组中获得机器人。当Sticker,Gif或Voice被发送到组时,应该删除机器人。但机器人不会删除它们.bot代码:

from telegram.ext import Updater, MessageHandler, Filters

def sticker_method(bot, update):
    bot.delete_sticker(chat_id = update.message.chat_id, sticker_id = update.sticker.chat_id)
    bot.delete_gif(chat_id = update.message.chat_id, gif_id = update.gif.chat_id)
    bot.delete_voice(chat_id = update.message.chat_id, voice_id = update.voice.chat_id)


def main():
    updater = Updater(token='TOKEN')
    dispatcher = updater.dispatcher
    dispatcher.add_handler(MessageHandler(Filters.all, sticker_method))

    updater.start_polling()
    updater.idle()


if __name__ == '__main__':
    main()
# for exit
# updater.idle()

执行期间没有错误;但机器人什么也没做!

1 个答案:

答案 0 :(得分:0)

此库中没有delete_stickerdelete_gifdelete_voice方法。您要找的是bot.delete_message()

您还可以使用一些广泛的过滤器,例如Filters.stickerFilters.voice

更多信息(已编辑):

例如,你可以这样做(使用Filters.stickerMessage.delete()):

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


def main():
    updater = Updater(token='TOKEN')
    dispatcher = updater.dispatcher
    dispatcher.add_handler(MessageHandler(Filters.sticker, delete_sticker_callback))

    updater.start_polling()
    updater.idle()


if __name__ == '__main__':
    main()