Skip to content

Instantly share code, notes, and snippets.

@Bergiu
Created May 28, 2018 15:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bergiu/ab3a4d8f2bedeb2a6cc1e57d63efceca to your computer and use it in GitHub Desktop.
Save Bergiu/ab3a4d8f2bedeb2a6cc1e57d63efceca to your computer and use it in GitHub Desktop.
Small Telegram-Bot that removes all /commands
#!/usr/bin/env python3
# requirements:
# - [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot/)
# - `pip3 install python-telegram-bot`
from telegram.ext import CommandHandler, MessageHandler, Filters, Updater
from telegram import Message, Update, Bot
from telegram.ext import BaseFilter
import logging
# TODO: replace with your token from [@botfather](https://t.me/botfather)
token = ""
class BlueText(BaseFilter):
def filter(self, message: Message):
if message.text.find("/") == 0:
return True
return False
def remove_bluetext(bot: Bot, update: Update):
bot.delete_message(
chat_id=update.message.chat_id,
message_id=update.message.message_id)
# bot
updater = Updater(token=token)
dispatcher = updater.dispatcher
# logging
logform = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(format=logform, level=logging.INFO)
# Remember to initialize the class.
remove_handler = MessageHandler(BlueText(), remove_bluetext)
dispatcher.add_handler(remove_handler)
# start bot
updater.start_polling()
print("Bot is running.")
# wait till sigint
updater.idle()
@edgarcornelius
Copy link

Danke, ich muss mal schauen ob ich das in mein bestehendes Projekt einbauen kann.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment