I
I
IlyaAkt2021-05-03 18:54:10
Python
IlyaAkt, 2021-05-03 18:54:10

How to make a VK bot ignore the user id that forbade sending him messages?

I have such code

elif "!Рассылка" in reseived_message:
          for id in users:
            user_id=id
            write_messages_us(id, (re.sub(r'!Рассылка', " ", reseived_message)))

When someone writes !Mailout "message", this message is sent to all users whose id I have added. Is it possible to somehow make the bot skip the id of the person who did not grant the right to send messages to him, otherwise an error pops up:
vk_api.exceptions.ApiError: [901] Can't send messages for users without permission
and the bot stops working

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Antonov, 2021-05-03
@IlyaAkt

Do it in this way:

for id in users:
            user_id=id
            try:
                write_messages_us(id, (re.sub(r'!Рассылка', " ", reseived_message)))
            except Exception:
                pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question