T
T
Toxs1k2019-11-15 21:35:34
In contact with
Toxs1k, 2019-11-15 21:35:34

How to make the bot react to messages that you reply to, and not forward?

def isAdmins(event, cmd):
  if event.type == VkBotEventType.MESSAGE_NEW and event.object.text.lower() == cmd:
    if event.obj.from_id in admins:
      return True
  return False

while True:
  try:
    for event in longpoll.listen():

      if isAdmins(event, 'kick' and 'кик'):
        if event.obj["fwd_messages"]:
          user_id = event.obj["fwd_messages"][0]["from_id"]
          vk.messages.send(peer_id=event.object.peer_id, sticker_id='11724', message='Исключаю @id' + str(user_id) + '(пользователя)...' '\n❌ Бан на сутки!\n После истечения срока написать ... или ...\n Чтобы узнать правила напишите в @letsbot (ЛС боту) "Правила".', random_id=0)
          time.sleep(1)
          vk.messages.removeChatUser(chat_id=event.chat_id, user_id=user_id, member_id=user_id)
          vk.messages.send(peer_id=event.object.peer_id, message='@id' + str(user_id) + '(Пользователь) был успешно исключён из беседы на сутки ✔.', random_id=0)
  
  except Exception as e:
   print(e)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Neverov, 2019-11-15
@Toxs1k

Read the documentation for the message type.
Each forwarded message is passed in the fwd_messages field, if this field is not present or it is empty, the message is not forwarded.

S
Stockholm Syndrome, 2019-11-15
@StockholmSyndrome

user_id = event.obj["reply_message"]["from_id"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question