Answer the question
In order to leave comments, you need to log in
How to output data in one line from a for loop?
There is this code:
for i in event.raw['object']['attachments']:
attachments1 = i['type']
try:
attachments = attachments1 + str(i[attachments1]['owner_id']) + '_' + str(i[attachments1]['id']) + '_' + str(i[attachments1]['access_key']) + ','
except:
attachments = attachments1 + str(i[attachments1]['owner_id']) + '_' + str(i[attachments1]['id']) + ','
vk.method('messages.send', {'peer_id': event.object.peer_id, 'message': event.object.text[5:], 'attachment': attachments, 'random_id': 0})
Answer the question
In order to leave comments, you need to log in
var widthCol = 0;
var i = 0;
var flag = true;
while (flag) {
i++;
if ($("div").is('.col-' + i)) {
$('.col-' + i).each(function(index, el) {
var temp = $(this).innerWidth();
if (temp > widthCol) {
widthCol = temp;
}
});
$('.col-' + i).css({
width: widthCol
});
widthCol = 0;
}else{
flag = false;
}
}
Sending a message inside a loop, which is why each attachment is sent separately in each message. As I understand it, it is necessary to send all attachments from the event, then we do this:
attachments = ""
for i in event.raw['object']['attachments']:
attachments1 = i['type']
try:
attach = attachments1 + str(i[attachments1]['owner_id']) + '_' + str(i[attachments1]['id']) + '_' + str(i[attachments1]['access_key']) + ','
attachments += attach
except:
attach = attachments1 + str(i[attachments1]['owner_id']) + '_' + str(i[attachments1]['id']) + ','
attachments += attach
vk.method('messages.send', {'peer_id': event.object.peer_id, 'message': event.object.text[5:], 'attachment': attachments, 'random_id': 0})
attachments = []
eventAttachments = event.raw['object']['attachments']
for attachment in eventAttachments:
attach = "%s%s_%s" % (attachment['type'], attachment['owner_id'], attachment['id'])
if 'access_key' in attachment:
attach += "_%s" % attachment['access_key']
attachments.append(attach)
vk.method('messages.send', {'peer_id': event.object.peer_id, 'message': event.object.text[5:], 'attachment': ','.join(attachments), 'random_id': 0})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question