A
A
AlexHDreal2020-07-12 12:34:16
Python
AlexHDreal, 2020-07-12 12:34:16

Which cycle is better to choose, how to implement variable substitution??

The function of deleting a message in the Telegram bot on aiogram.
There is a .txt file in which there are numbers written line by line (user id and message id)
There are a lot of them. Each user id has its own post id. The data file can be changed as you like for ease of use.
It is necessary to organize the substitution of all data one by one in "bot.delete_message()" and loop this process so that the procedure is performed for all values ​​in the data file.

#Удаление сообщений

    @dp.message_handler(Text(equals=["delmess"]))
    async def delete_links(message: types.Message):
        if int(message.chat.id) == config.owner:
            await bot.delete_message(281521204, 1735)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cappietrol, 2020-08-15
@Cappietrol

As far as I understand, the decorator means that the delete_links function is called if a message containing delmess has arrived.
First you have to read the file -> https://pythonworld.ru/tipy-dannyx-v-python/fajly-...
Next, you divide the received lines into two numbers (using split if the separator is known or through regular expressions) and you will get a list where each element will contain two values ​​like this a = .
Then you do a for loop for this list

for user_id, mess_in in arr:
...

And then either you collect a pack of tasks and then execute them through gather, or you start it like this. Depending on logic.
If something is not clear, write, I will explain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question