0

ВК бот зацикливается на одном сообщении. Подскажите, как исправить данную проблему.

    static void Main(string[] args)
    {
        var api = new VkApi();
        api.Authorize(new ApiAuthParams() { AccessToken = MyAppToken });

        var s = api.Groups.GetLongPollServer(MyGroupId);            

        while(true)
        {
            BotsLongPollHistoryResponse poll = api.Groups.GetBotsLongPollHistory(
                                  new BotsLongPollHistoryParams()
                                  { Server = s.Server, Ts = s.Ts, Key = s.Key, Wait = 20 });

            if (poll?.Updates == null) continue;

            foreach (var a in poll.Updates)
            {
                if (a.Type == GroupUpdateType.MessageNew)
                {
                    Console.WriteLine(a.Message.Body);
                    api.Messages.Send(new MessagesSendParams()
                    {
                        UserId = a.Message.UserId,
                        Message = a.Message.Body,
                        RandomId = new Random().Next(),
                    });
                }
            }
        }
    }
0

1 ответ 1

0

Вы забыли обновлять s.Ts без этого у вас бот не "движется" вперед

Надо добавить

s.Ts = poll?.Ts;

перед

if (poll?.Updates == null) continue;

1
  • Большое спасибо 19 июн 2020 в 14:52

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.