Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Цикл останавливается #507

Closed
amin4ik003 opened this issue Aug 20, 2022 · 0 comments
Closed

Цикл останавливается #507

amin4ik003 opened this issue Aug 20, 2022 · 0 comments
Labels
package: vk-io Issues related to vk-io

Comments

@amin4ik003
Copy link

hm.hear(/(рассылка)/ui, async (ctx) => {
    if(ctx.senderId != 1) {
        return ctx.send(`
❗ Произошла ошибка!
— У Вас недостаточно прав!`)
    }
    if(!ctx.text.split(' ')[2]) {
        return ctx.send(`
❗ Неверно введена команда!
— Использование команды: Рассылка «вложение» «текст»`);
    }
    User.find({}, function(err, users) {
        let sendcount = 0;
    
        users.forEach(function(user) {
          sendcount += 1;
          ctx.send(`${ctx.text.replace(ctx.text.split(' ')[0], '').replace(ctx.text.split(' ')[1], '')}`, {user_id: user.id, attachment: ctx.text.split(' ')[1]});
        });
        ctx.send(`⚙ Отправлено сообщений: ${sendcount}`)
      });
});

Показывает ошибку

H:\devs\nodejs\dd\node_modules\vk-io\lib\index.js:1670
            this.handleError(request, new APIError(response.error));
                                      ^

APIError: Code №901 - Can't send messages for users without permission
    at SequentialWorker.execute (H:\devs\nodejs\dd\node_modules\vk-io\lib\index.js:1670:39)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 901,
  params: [
    { key: 'method', value: 'messages.send' },
    { key: 'oauth', value: '1' },
    { key: 'v', value: '5.131' },
    { key: 'random_id', value: '15693356884120712' },
    { key: 'peer_id', value: '311527967' },
    { key: 'attachment', value: 'wall-215282978_177' },
    { key: 'peer_ids', value: '311527966' }
  ]
}

Хочу сделать рассылку в сообществе вк но при первой же ошибке о том что пользователь запретил отправку сообщений цикл останавливается и рассылка не идет дальше :( как этого избежать? может можно как-то проигнорировать ошибку и продолжить цикл?

@amin4ik003 amin4ik003 added the package: vk-io Issues related to vk-io label Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: vk-io Issues related to vk-io
Projects
None yet
Development

No branches or pull requests

1 participant