To send a message, you must specify the random_id, and it is obtained through get_random_id, but the program cannot find it.

# -* -coding: utf-8 -* -
import requests
import vk_api
from vk_api import VkUpload
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.utils import get_random_id
def main ():
    login, password= 'mail', 'pass'
    vk_session= vk_api.VkApi (login, password)
        vk_session.auth (token_only= True)
    except vk_api.AuthError as error_msg:
        print (error_msg)
    longpoll= VkLongPoll (vk_session)
    vk= vk_session.get_api ()
    for event in longpoll.listen ():
        if event.type== VkEventType.MESSAGE_NEW and event.to_me and event.text:
           if event.text== 'hello':
                if event.from_chat:
                    vk.messages.send (
                        user_id= event.user_id,
                        random_id= get_random_id (),
                        message= 'bye'
if __name__== '__main__':
    main ()

Error No name 'get_random_id' in module 'vk_api.utils' How can this be fixed or what can replace get_random_id

  • Answer # 1

    For everyone who encountered this problem. Update vk_api library to 11.4.0 via pip or repository.