Y
Y
y_o_l_k_i_n___e_g_o_r2021-10-22 19:35:48
Python
y_o_l_k_i_n___e_g_o_r, 2021-10-22 19:35:48

How to make mass mailing instant?

Good evening, Harbchane.
There was a question. I send a mass mailing to about 400 people in the bot through the vk_api library. At this time, the bot lags and does not respond to other messages. Enlighten on how to make the mailing instant and so that during the mailing the bot will respond to other messages?

Message sending code:

async def send_message(event, text='', keyboard=None,
                       user_id=None,
                       attachment=None):  # функция отправки сообщений
    if user_id is None:
        user_id = event.user_id
    try:
        vk.messages.send(
            user_id=user_id,
            message=text,
            random_id=0,
            keyboard=keyboard,
            attachment=attachment
        )
        return True
    except:
        return False

--
Distribution code:
users = database.execute(f'SELECT user_id FROM users').fetchall()

                            for i in users:
                                await send_message(event, text, keyboard=commands_keyboard.get_keyboard(), user_id=i[0])


Thanks in advance for your reply

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ScriptKiddo, 2021-10-22
@ScriptKiddo

vk_api is a synchronous library, it has the ability to limit the frequency of sending messages so as not to fall under the VK restrictions of 3 API calls per second
https://github.com/python273/vk_api/blob/a4d26e2a6...
Therefore, everything slows down, because that time.sleep() blocks the execution of an asynchronous program. Use the aiovk
asynchronous library - this will get rid of the "lags" of the bot when sending

P
Puma Thailand, 2021-10-23
@opium

Take a server with more cores and proxies and send your spam in parallel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question