for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.from_chat and event.object['photos'] !="": #Получение сигнала на то, что пришло сообщение
msg = event.object['photos']
id = event.chat_id
print("plant A")
#удаляем данное сообщение...
KeyError: 'photos'
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.obj.attachments != []:
if event.obj.attachments[0]['type'] == 'photo':
....
elif event.obj.attachments[0]['type'] == 'wall':
....
elif event.obj.attachments[0]['type'] == 'video':
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
try:
if event.obj.attachments != []:
if event.obj.attachments[0]['type'] == 'photo':
print("A")
elif event.obj.attachments[0]['type'] == 'wall':
print("B")
elif event.obj.attachments[0]['type'] == 'video':
print("C")
else:
print("D")
except:
print("Тип не найден.")
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
import time, datetime
def write_message(id, message):
vk.method('messages.send', {'chat_id': id, 'message': message, 'random_id': 123456})
token = "ТОКЕН"
vk = vk_api.VkApi(token=token) # Авторизуемся как сообщество
longpoll = VkBotLongPoll(vk, group_id = 'ID ГРУППЫ')
print("Бот запущен")
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
try:
if event.obj.attachments != []:
if event.obj.attachments[0]['type'] == 'photo':
print("A")
elif event.obj.attachments[0]['type'] == 'wall':
print("B")
elif event.obj.attachments[0]['type'] == 'video':
print("C")
else:
print("D")
except:
print("Тип не найден.")
else:
pass #Игнорирует все сообщения кроме выше...