M
M
Maxim Yumikov2020-08-11 14:52:51
Python
Maxim Yumikov, 2020-08-11 14:52:51

How to make a greeting when adding the same bot?

Hello Habr! I am making a chat bot and I want to make a greeting when the same bot is added. I found it in the documentation only when adding other users (maybe I'm blind and didn't see what it was). Thank you in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Yumikov, 2021-05-03
@OhMySenpai

I climbed the profile, but I didn’t mark the solution here, so there will be my option

if event.type == VkBotEventType.MESSAGE_NEW and (action := event.obj['message'].get('action')):
            if action['type'] == 'chat_invite_user' and action["member_id"] == -12345678: #вместо -12345678 айди группы с минусом
                vk.messages.send(
                    peer_id=event.message.peer_id,
                    random_id=get_random_id(),
                    message="Привет")

A
Artur, 2020-08-11
@rackev

I would implement it somehow like this

import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id

vk_session = vk_api.VkApi(token="tokengroup")  

longpoll = VkBotLongPoll(vk_session, 'idgroup')  

vk = vk_session.get_api()

while True:
    try:
        for event in longpoll.listen():
            if event.type == VkBotEventType.MESSAGE_NEW and event.raw['object']['message']['action']['type'] == 'chat_invite_user' and event.raw['object']['message']['action']['member_id'] == -12345678:  #вместо -12345678 впишите id своей группы
                vk.messages.send(
                    peer_id=event.message.peer_id,
                    random_id=get_random_id(),
                    message="Тест"
                )
    except Exception as e:
        print(e)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question