A
A
Anonymous Coder2021-01-14 06:13:14
Python
Anonymous Coder, 2021-01-14 06:13:14

Delete all user messages in Telegram group?

I'm trying to make it so that when I reply to a message with the text /start in the group - all messages of the person whose message I replied to - are deleted.

Below is a snippet of code that only works before the user id is printed. checked with a print if it recognizes id. recognizes .. and then - for some reason in any way .. I don’t see the problem

TELEBOT

@bot.message_handler(commands=["mute"])  #
def channel_message(message):  #Создаем функцию
    if message.from_user.id == config.admin_id:
        if message.chat.type != "private":
            print(message.reply_to_message.from_user.id)
            for i in range(0, message.message_id):
                try:
                    bot.delete_message(message.reply_to_message.from_user.id, i)
                except:
                    pass

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-01-14
@SoreMix

Because deleteMessage takes the chat ID as the first argument, not the user ID.
The right way to delete all messages from a channel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question