N
N
Nikita Kuzovkov2019-10-14 18:47:58
Python
Nikita Kuzovkov, 2019-10-14 18:47:58

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})

here she is,
I don't understand what's wrong

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Araik, 2019-10-14
@NinjaNickName

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.

https://vk.com/dev/permissions
https://vk.com/dev/access_token

D
Duzive, 2019-10-14
@duzive

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("произошла ошибка!")

F
Febel, 2019-12-05
@Febel

Just go to group settings. Create a new token and give permission to send messages. In the code, replace the old token with the new one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question