Home computickets how to make vk_api could remember with who to communicate

how to make vk_api could remember with who to communicate




How to make a bot in VK could take the Nick of the user from the profile, and how an example could write when the user has a birthday. Wrote him congratulations

Answer 1

For information about Nika and the date of birth, you can use the Users.get .


from vk_api import vkapi
vk_session = vkapi (token = '[token]')
vk = vk_session.get_api ()
R = vk.users.get (user_ids = 1, fields = 'screen_name, bdate') [0]
Print (F "Nick: {R ['screen_name']} \ NDA Birth: {R ['BDATE']}")


nickname: DUROV
Date of birth: 10/10/1984

Precept for the bot (Long Poll v5.103):

from vk_api import vkapi
from vk_api.bot_longpoll import vkbotlongpoll, vkboteventtype
from vk_api.utils import get_random_id
Access_Token = '' # Substitute your!
Group_id = # Substitute your!
DEF Main ():
  vk_session = vkapi (token = access_token)
  vk = vk_session.get_api ()
  For event in longpoll.listen ():
    If event.Type == vkboteventtype.Message_New:
      Message = event.obj ['Message']
      User_ID = Message ['from_id']
      user_info = vk.users.get (user_ids = user_id, fields = 'screen_name, bdate') [0]
      screen_name = user_info.get ('screen_name')
      BDATE = user_info.get ('BDATE')
      vk.messages.send (
        peer_id = Message ['peer_id'],
        Message = F'Name: {Screen_Name} \ Nadea Birth: {BDATE} ',
        random_id = get_random_id (),
if __name__ == '__main__':
  Main ()

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions