G
G
Grafixy2020-09-05 21:07:56
Bots
Grafixy, 2020-09-05 21:07:56

How to automatically delete a message in a telegram group if it contains a certain word?

Tell the moderator bot to delete any message in the group containing the specified word.
The list of prohibited words would like to be edited.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Grafixy, 2020-09-08
@Grafixy

For those who have the same issue, I found a solution. The solution is obvious - I wrote my bot.
Here is the code:

import telebot

token='Токен_который_дает_BotFather'
bot = telebot.TeleBot(token)
GROUP_ID=ID_чата_которое_дает[email protected]
blacklist=['слово_которое_нужно_удалять']
@bot.message_handler(content_types=["text"])
def handle_text(message):
    for x in blacklist:
        if(x in message.text):
            bot.delete_message(message.chat.id, message.message_id)
        else:
            pass
        
if __name__ == "__main__":
    bot.infinity_polling()

The whole thing is hung on the VPS server, you can add as many words as you like. How to register a bot, I don’t write a chat ID - there are a lot of instructions

I
IKIQ, 2020-09-05
@IKIQ

https://mastergroosha.github.io/telegram-tutorial/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question