A
A
Artur2020-05-29 12:24:55
Python
Artur, 2020-05-29 12:24:55

How to make sure that the bot does not break if another community writes to the conversation?

The bot crashes if another community writes to the conversation, cannot process its message

for event in longpoll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW: #Слушаем longpoll, если пришло сообщение то:
            response = str(event.message.text)
            user_id = str(event.message.from_id)
            user = vk.users.get(user_ids=user_id)

            elif word == 'дата' or word == 'время' or word == '!time' or word == 'какой сегодня день':
                if event.from_chat:
                        vk.messages.send( #Отправляем сообщение
                            chat_id=event.chat_id, #Здесь chat_id
                            random_id=get_random_id(),
                            message='Сегодня: ' + message_time,
                        )


Mistake:

vk_api.exceptions.ApiError: [113] Invalid user id

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2020-05-29
@rackev

Check in event where the message came from, from a group or user
https://vk-api.readthedocs.io/en/latest/_modules/v...

A
alfss, 2020-05-29
@alfss

Make exception handling

I
ishmatov_rus, 2020-05-29
@ishmatov_rus

How do you even get it started?
1. The indents are not correct
2. Store the message in the response, and compare it with some kind of word

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question