Answer the question
In order to leave comments, you need to log in
I'm making a bot in VK for a conversation?
vk_api.exceptions.ApiError: [15] Access denied: no access to call this method
is what the program gives me
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api
import time
vk = vk_api.VkApi(token="токен")
vk.get_api()
longpoll = VkBotLongPoll(vk, "ид группы")
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
if event.object.text.lower() == "привет":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "привет",
"random_id": 0})
elif event.object.peer_id == event.object.from_id:
if event.object.text.lower() == "привет":
vk.method("messages.send", {"user_id": event.object.from_id, "message":"привеет",
"random_id": 0})
Answer the question
In order to leave comments, you need to log in
Access rights determine the ability to use the token to work with a particular section of data. So, for example, to send a private message on behalf of a user, the token must be obtained with the messages rights.
The list of access rights names that the application needs, or the sum of their bitmasks, is passed in the scope parameter during the process of obtaining the access token.
See error codes. #15 exits with invalid data. Check the token/id of the group. Also check the permissions for Longpull. It is also worth making the code more readable. For example:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
request = event.obj.text.lower() #будем сохранять в переменную ответ
if request == "привет":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "привет", "random_id": 0})
#но лучше конечно создать функцию для обработки сообщений
except #код ошибки as e:
print("произошла ошибка!")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question