Answer the question
In order to leave comments, you need to log in
How to write the correct sequence of bot actions?
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
print("Текст сообщения: " + event.text)
ans = event.text.lower()
res = vk_session.method("messages.getById", {"message_ids": [event.message_id], "group_id": 196640056})
if ans == "1":
vk_session.method('messages.send', {'user_id': event.user_id, "message": 'Отправь фото', 'random_id': get_random_id()})
if event.type == VkEventType.MESSAGE_NEW and event.to_me and not event.text:
# Дальше код не идет
vk_session.method('messages.send', {'user_id': event.user_id, "message": 'Как называется ваше достижение? ', 'random_id': get_random_id()})
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
big_text = event.text
try:
image_url = res['items'][0]['attachments'][0]['photo']['sizes'][0]
url = '{}'.format(image_url['url']) #Получает url
urlretrieve(url, "photo.png")
except:
pass
Answer the question
In order to leave comments, you need to log in
Something like this:
vk_s = vk_api.VkApi(token='token')
api = vk_s.get_api()
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
msg = event.text.split(' ')
print('Текст сообщения: {}'.format(event.text))
if msg[0] == '1':
try:
mess = api.messages.getById(message_ids=event.message_id)
image_url = mess['items'][0]['attachments'][0]['photo']['sizes'][0]
url = '{}'.format(image_url['url'])
text = event.text.replace("1", "")
if text == '':
api.messages.send(message="Как называется ваше достижение?", user_id=event.user_id, random_id=0)
else:
api.messages.send(message="Ваша фотография: {}\n\nВаше достижение: {}".format(url, text), user_id=event.user_id, random_id=0)
except IndexError:
api.messages.send(message="Отправь мне фото", user_id=event.user_id, random_id=0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question