K
K
Kropovniczky2022-02-09 20:34:40
JavaScript
Kropovniczky, 2022-02-09 20:34:40

Why does it output to the console as it should (6 groups), but only 1 group writes to messages?

The code:

cmd.hear(/^(?:1)$/i, async (msg) => {
        vk.api.groups.get({
            access_token: "",
            user_id: ,
            extended: 1,
            filter: "moder",
        }).then(function(res) {
            console.log(res)
            for (i in res.items) {
                return msg.send(`Список групп, в которых данный пользователь является администратором:\n[vk.com/club${res.items[i].id}|${res.items[i].name}]`)
                }
        })
    })


Everything finds correctly, the answer in the console is about 6 groups. But for some reason, when I want to display in a message, it displays only 1 group. Why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2022-02-09
@Kropovniczky

Because you have a return in the loop, which immediately completes it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question