Answer the question
In order to leave comments, you need to log in
Why does the bot on VkBotLongPoll duplicate responses to messages?
There is some bot using VkBotLongPoll. The logic, in principle, is simple: authorization, creation of a list of names and responses to unrecognized commands, command dictionaries in the format "command text: response", and a message handler function:
def message_type(self, message: str) -> str:
"""
Функция определения типа сообщения
:param message: текст сообщения
"""
for name in self.NAMES:
if message.startswith(name):
message_words = message.split()
other_text_list = message_words
other_text_list.pop(0)
command = ' '.join(other_text_list)
if command in self.PHRASES:
return random.choice(self.PHRASES[command])
elif command not in self.PHRASES and command not in self.COMMANDS:
return random.choice(self.COMMAND_NOT_STATED)
elif message == 'да':
return self.MEMES[message]
elif message in self.MEMES:
return self.MEMES[message]
def listen(self):
"""
Основной цикл, реагирующий на события
"""
for event in self.longpoll.listen():
try:
if event.type == VkBotEventType.MESSAGE_NEW:
self.text = event.object['text'].lower()
self.result = self.message_type(message=self.text)
if self.result:
if event.from_user:
self.send_message(id_=event.object['from_id'], message=self.result)
elif event.from_chat:
self.send_message(id_=event.object['peer_id'], message=self.result)
except requests.exceptions.ReadTimeout:
print('Reconnection...')
self.listen()
Answer the question
In order to leave comments, you need to log in
I think because you pointed out
elif message == 'да':
return self.MEMES[message]
elif message in self.MEMES:
return self.MEMES[message]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question