Z
Z
zbtacnbivndjaborxt2020-05-20 17:18:32
Python
zbtacnbivndjaborxt, 2020-05-20 17:18:32

How to accept the ref parameter in vk_api?

Hello, I have a bot written on vk_api.
I'm trying to make a referral system. I read on this page that there is a ref parameter
Please tell me how can I get it through vk_api?

My bot code:

# -*- coding: utf-8 -*-

import requests
import vk_api
import sqlite3
from vk_api.keyboard import VkKeyboard, VkKeyboardColor
from vk_api.longpoll import VkLongPoll, VkEventType
import random
import keyboards

import texts

vk_session = vk_api.VkApi(token='токен')

longpoll = VkLongPoll(vk_session, group_id=айди)
vk = vk_session.get_api()



def get_user_name(user_id):
    first = vk.users.get(user_id=user_id)[0]['first_name']
    last = vk.users.get(user_id=user_id)[0]['last_name']
    text = f'{first} {last}'
    return text


for event in longpoll.listen():
    
    if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
        if event.text.lower() == 'Начать'.lower() or event.text.lower() == 'Старт'.lower() or event.text.lower() == '↪️ В главное меню ↩️'.lower() or event.text.lower() == '/start'.lower() or event.text.lower() =='Привет'.lower(): #Если написали заданную фразу
            if event.from_user:
                connection = sqlite3.connect('database.sqlite')
                q = connection.cursor() 
                q.execute(f"SELECT userid FROM ugc_users")
                userid = q.fetchone()
                if userid == None:
                    q.execute("INSERT INTO ugc_users (userid,name) VALUES ('%s','%s')"%(event.user_id,get_user_name(event.user_id)))
                    connection.commit()
                    vk.messages.send(user_id=event.user_id,message=f'{texts.main_text()}' ,random_id=random.randint(1,99999999999999),keyboard=keyboards.keyboard_main.get_keyboard())
                else:
                    vk.messages.send(user_id=event.user_id,message=f'{texts.new_user(event.from_user)}' ,random_id=random.randint(1,99999999999999),keyboard=keyboards.keyboard_start.get_keyboard())





            elif event.text.lower() == '☑️'.lower(): #Если написали заданную фразу
                if event.from_user: #Если написали в ЛС
                    vk.messages.send( #Отправляем сообщение
                        user_id=event.user_id,
                        message='Успешно' ,
                        random_id=random.randint(1,99999999999999),
                        keyboard=keyboards.keyboard_url(event.user_id).get_keyboard())


            elif event.text.lower() == ' Информация'.lower(): #Если написали заданную фразу
                if event.from_user:
                    vk.messages.send(user_id=event.user_id,message=f'{texts.info()}',random_id=random.randint(1,99999999999999))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vkulik79, 2020-05-23
@vkulik79

Hello, you need to refer to the event (you have an event).
Try this
event.obj.ref

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question