Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import vk_api
- from vk_api.longpoll import VkLongPoll, VkEventType
- import time
- import random
- def main():
- login, password = '*', '*'
- vk_session = vk_api.VkApi(login, password)
- try:
- vk_session.auth(token_only=True)
- except vk_api.AuthError as error_msg:
- print(error_msg)
- return
- vk = vk_session.get_api()
- longpoll = VkLongPoll(vk_session)
- for event in longpoll.listen():
- if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
- print('Новое сообщение')
- if event.from_user:
- while True:
- vk.messages.send(
- user_id=event.user_id,
- message='',
- random_id=random.randint(0, 111111111)
- )
- time.sleep(2)
- if event.from_chat:
- while True:
- vk.messages.send(
- chat_id=event.chat_id,
- message='',
- random_id=random.randint(0, 111111111)
- )
- time.sleep(2)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement