S
S
Snowdevil2021-06-05 23:10:06
Python
Snowdevil, 2021-06-05 23:10:06

Why doesn't the code section work?

After the timer, the code does not work, although there are no errors in the console.

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from toks import main_token
import time

vk_session = vk_api.VkApi(token = main_token)
longpoll = VkLongPoll(vk_session)
timing = time.time()

def sender(id, text):
    vk_session.method('messages.send', {'chat_id' : id, 'message' : text, 'random_id' : 0})

for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        if event.to_me:
            if event.from_chat:
                
                msg = event.text.lower()
                id = event.chat_id

                while True:
                    if time.time() - timing > 60.0:
                        timing = time.time()
                        #print("1 seconds")
                        sender(id, 'Раз, раз!')

                if msg == 'привет' or msg == 'здрастить' or msg == 'здраститя' or msg == 'приветствую':
                    sender(id, 'Здрастить! Здраститя... здраститя!')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-06-05
@Snowdevil

Well, I don’t even see break from the loop, so it twists while True forever.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question