R
R
re-incarnation2021-05-19 19:28:52
API
re-incarnation, 2021-05-19 19:28:52

Vk longpoll api where is the error?

I am writing a simple bot on SDK from "/SevereCloud/vksdk" , an error appears when responding to a message in a VK conversation, it says "api: You don't have access to this chat
exit status 1"
There are administrator rights in the conversation, event types are in the settings community "Messages" included.
Here is the code:

package main

import (
  "context"
  "log"

  "github.com/SevereCloud/vksdk/v2/api"
  "github.com/SevereCloud/vksdk/v2/api/params"
  "github.com/SevereCloud/vksdk/v2/events"
  "github.com/SevereCloud/vksdk/v2/longpoll-bot"
)

func main() {
  token := "****" 
  vk := api.NewVK(token)

  
  group, err := vk.GroupsGetByID(nil)
  if err != nil {
    log.Fatal(err)
  }

  
  lp, err := longpoll.NewLongPoll(vk, group[0].ID)
  if err != nil {
    log.Fatal(err)
  }

  lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
         log.Printf("%d: %s", obj.Message.PeerID, obj.Message.Text)
    if obj.Message.Text == "test" {
      b := params.NewMessagesSendBuilder()
      b.Message("test 2")
      b.RandomID(0)
      b.PeerID(2000000266)

      _, err := vk.MessagesSend(b.Params)
      if err != nil {
        log.Fatal(err)
      }
    }
  })

  
  log.Println("Start Long Poll")
  if err := lp.Run(); err != nil {
    log.Fatal(err)
  }
}


When I write a message in a conversation, it displays it in the console, but when the message specified in if is triggered, it turns off with an error
You don't have access to this chat
exit status 1

What is the problem and how to solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WolfInChains, 2021-05-19
@re-incarnation

Maybe it's the peer_id. Bots and pages are different. Try printing it to the console when you receive a new message and compare.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question