Created
October 30, 2022 13:26
-
-
Save JoshuaJakowlew/c73d89d4ce32629c5490198b9e92027b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vk_api | |
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType | |
def main(): | |
""" Пример использования bots longpoll | |
https://vk.com/dev/bots_longpoll | |
""" | |
vk_session = vk_api.VkApi(token='vk1.a.d3FAEBsnN64l1MjO7QTHldPgj-2HiTFtLxXvwgIGvoBClCAy-4KEPF9BVsczo0JBTREYkQbQMpyT7iolGeGaGUA3c2WVGuE_vJOQZE6ZliIod844VFmEh5UpY9OMF6skYdHlOMmRSBWYAh4Sq_MiSJ_6LzAdpGByX6If6PhccvXKwqxD2PerG4fz3mSgPU2zbjMCYodwzcrZiOOW5vQArQ') | |
longpoll = VkBotLongPoll(vk_session, '216882603') | |
for event in longpoll.listen(): | |
if event.type == VkBotEventType.MESSAGE_NEW: | |
print('Новое сообщение:') | |
print('Для меня от: ', end='') | |
print(event.obj.from_id) | |
print('Текст:', event.obj.text) | |
print() | |
elif event.type == VkBotEventType.MESSAGE_REPLY: | |
print('Новое сообщение:') | |
print('От меня для: ', end='') | |
print(event.obj.peer_id) | |
print('Текст:', event.obj.text) | |
print() | |
elif event.type == VkBotEventType.MESSAGE_TYPING_STATE: | |
print('Печатает ', end='') | |
print(event.obj.from_id, end=' ') | |
print('для ', end='') | |
print(event.obj.to_id) | |
print() | |
elif event.type == VkBotEventType.GROUP_JOIN: | |
print(event.obj.user_id, end=' ') | |
print('Вступил в группу!') | |
print() | |
elif event.type == VkBotEventType.GROUP_LEAVE: | |
print(event.obj.user_id, end=' ') | |
print('Покинул группу!') | |
print() | |
else: | |
print(event.type) | |
print() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment