I
I
IlyaAkt2021-05-03 23:02:30
Python
IlyaAkt, 2021-05-03 23:02:30

Why VK bot replies 2 times?

There is such a code

def write_messages(sender, message):
      authorize.method('messages.send', {'chat_id': sender, 'message': message, 'random_id': get_random_id(), 'attachment': ','.join(attachments)})
def write_messages_us(user_id, message):
      authorize.method('messages.send', {'peer_id': user_id, 'message': message, 'random_id': get_random_id(), 'attachment': ','.join(attachments)})
users = [id пользователя, id второго пользователя]
for id in users:
            user_id=id
            if id == 'id пользователя':
              try:
                write_messages_us(id, (re.sub(r'!Рассылка', " ", reseived_message)))
              except Exception as ex:
                print("Ошибка")
            else:
              write_messages(sender, "А у тебя нет прав на эту команду")

When a person who is allowed to make a mailout (!Mailout) then everything is fine, but when a person who is forbidden to do it writes the command!Mailout, then the bot answers TWO times this: "But you do not have rights to this command." Why does he say this twice and how to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IlyaAkt, 2021-05-04
@IlyaAkt

I managed to fix it like this:

def write_messages(sender, message):
      authorize.method('messages.send', {'chat_id': sender, 'message': message, 'random_id': get_random_id(), 'attachment': ','.join(attachments)})
    def write_messages_us(id, message):
      authorize.method('messages.send', {'peer_id': id, 'message': message, 'random_id': get_random_id(), 'attachment': ','.join(attachments)})

elif re.findall('!Рассылка', reseived_message):
          if event.object.message['from_id'] in admins:
            for id in users:
              try:
                write_messages_us(id, (re.sub(r'!Рассылка', " ", reseived_message)))
              except Exception as ex:
                print("Ошибка")
          else:
            write_messages(sender, "У вас нет прав")

U
Uno, 2021-05-04
@Noizefan

users = [id пользователя, id второго пользователя]
for id in users:

how many times is it performed?
write_messages(sender, "А у тебя нет прав на эту команду")

so many times the sender comes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question