· 4 years ago · Aug 27, 2021, 06:14 AM
1using VkNet;
2using VkNet.Enums.Filters;
3using VkNet.Model.RequestParams;
4using VkNet.Model;
5using VkNet.Enums.SafetyEnums;
6
7namespace TestAndroid1
8{
9 class VkBot
10 {
11 private int state=1;
12
13 private VkApi api = new VkApi();
14
15 public VkBot() //это запускается первым
16 {
17 api.Authorize(new ApiAuthParams
18 {
19 AccessToken = "a2820442fc2ftoken" //токен группы
20 });
21 }
22
23 private void LongPoll() //это вторым
24 {
25 //тут ошибка в этой строке:
26 var s = api.Groups.GetLongPollServer((ulong)192183756/*айди той же группы, что и токен*/);
27 //VkNet.Exception.CannotBlacklistYourselfException:
28 //'Access denied: no access to call this method'
29 while (state==1)
30 {
31
32 var poll = api.Groups.GetBotsLongPollHistory(
33 new BotsLongPollHistoryParams()
34 { Server = s.Server, Ts = s.Ts, Key = s.Key, Wait = 1 });
35
36 if (poll?.Updates == null) continue; //пришло ли чет
37
38 foreach (var a in poll.Updates)//для всего че пришло
39 {
40 if (a.Type == GroupUpdateType.MessageNew) //если сообщение
41 {
42
43 api.Messages.Send(new MessagesSendParams() //че отправляем в ответ
44 {
45 UserId = a.Message.UserId,
46 Message = "AAAAAAAAAAAAA!!!."
47 });
48 }
49 }
50 }
51 }
52
53 }
54}