Answer the question
In order to leave comments, you need to log in
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
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])
Answer the question
In order to leave comments, you need to log in
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
Take a server with more cores and proxies and send your spam in parallel
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question