W
W
wirflve2021-09-15 22:49:51
Python
wirflve, 2021-09-15 22:49:51

How to stop the cycle by sending a message to VK?

I have code:

from vk_api import VkApi
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id

print("Работает")

vk_session = VkApi(token='токен')
long_poll = VkBotLongPoll(vk_session, 'айди сообщества')
vk = vk_session.get_api()


def autosend(spam):
    for i in range(int(spam) + 1):
        vk.messages.send(peer_id=peer_id, message=str(i), random_id=get_random_id())


for event in long_poll.listen():
    if event.type == VkBotEventType.MESSAGE_NEW:
        peer_id = event.obj['peer_id']
        message = event.obj['text'].lower()

        if message.startswith('autosend'):
            intspam = message[9:]
            autosend(intspam)

And I need it to stop spam after sending the message. How to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RINAMI, 2021-10-08
@RINAMI

while True:
    if message.startswith('autosend'):
          intspam = message[9:]
          autosend(intspam)
       if message == 'stop':
           break

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question