B
B
BabaManya2222022-01-17 22:35:45
Python
BabaManya222, 2022-01-17 22:35:45

The bot has stopped working. Where is the mistake?

At one point, it just stopped working, messages just go directly to the admins, as if there was no bot. Moreover, I did not make any changes to the code, just at one "perfect moment" the messages stopped working. I already tried to change the token, and sorted through all the code, and launched it from different servers, it’s just like there is no bot, messages go straight to the PM.
I could not find anything new in the VK documentation
https://dev.vk.com/api/bots/getting-started

import vk_api, random
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.keyboard import VkKeyboard, VkKeyboardColor
import json


token = "тут_токен_с_ним_всё_ок"

vk = vk_api.VkApi (token = token)
vk._auth_token()
longpoll = VkLongPoll(vk)


def add_button(text, color):
    return {
                "action": {
                    "type": "text",
                    "payload": "{\"button\": \"" + "1" + "\"}",
                    "label": f"{text}"
                },
                "color": f"{color}"
            }


keyboard = {
    "one_time" : True,
    "buttons" : [
        [add_button('Да :3', 'positive'), add_button('Неть -. -', 'negative')],
        [add_button('За видосиком!', 'primary'), add_button('Гифку хочу', 'primary')],
        [add_button('Написать Старосте Группы!','secondary')],
        [add_button('написать простому админу','secondary')],
        [add_button('Подписаться на рассылку!','positive')]

    ]
}
keyboard = json.dumps(keyboard, ensure_ascii = False).encode('utf-8')
keyboard = str(keyboard.decode('utf-8'))

keyboardone = {
    "one_time" : True,
    "buttons" : [
        [add_button('Хочу арт', 'positive'),add_button('Хочу фотку', 'positive')],
        [add_button('За видосиком!', 'primary'), add_button('Гифку хочу', 'primary')],
        [add_button('Написать Старосте Группы!','secondary')],
        [add_button('написать простому админу','secondary')],

    ]
}
keyboardone = json.dumps(keyboardone, ensure_ascii = False).encode('utf-8')
keyboardone = str(keyboardone.decode('utf-8'))

def sender (user_id, text):
   messages = vk.method("messages.getConversations",{"offset":0,"count":20,"filter":"unanswered"})
   a = ("photo-"+str(194057998)+"_"+str(random.randint(457239019,457270264)))
   b = ("photo-"+str(194057998)+"_"+str(random.randint(457239019,457270264)))
   c = ("photo-"+str(194057998)+"_"+str(random.randint(457239019,457270264)))
   d = ("photo-"+str(194057998)+"_"+str(random.randint(457239019,457270264)))
   exclude = range(457279073,457266641)
   while a in exclude:
    a = ("photo-"+str(194057998)+"_"+str(random.randint(457239019,457270264)))
   while b in exclude:
    b = ("photo-"+str(194057998)+"_"+str(random.randint(457239019,457270264)))
   while c in exclude:
    c = ("photo-"+str(194057998)+"_"+str(random.randint(457239019,457270264)))
   while d in exclude:
    d = ("photo-"+str(194057998)+"_"+str(random.randint(457239019,457270264)))
   fotka = random.choice([("photo-"+str(194057998)+"_"+str(random.randint(457282888,457282912))),("photo-"+str(194057998)+"_"+str(random.randint(457270272,457270302))), ("photo-"+str(194057998)+"_"+str(random.randint(457279073,457279105))), ("photo-"+str(194057998)+"_"+str(random.randint(457266381,457266641)))])
   
   
   if messages["count"] >= 1:
      text = messages['items'][0]['last_message']['text']
      user_id = messages['items'][0]['last_message']['from_id']
      if text.lower() in  ['давай попробуем ещё раз', 'ghbd', 'ghbdtn', 'привет', 'здоров', 'ку', 'хай', 'здарова', 'чокаво', 'прив', 'салют', 'шалом','арты','арт','начать','старт','смотреть арты','хелло','хеллоу']:
         vk.method("messages.send",{"user_id":user_id,"message":"Ага, ты за артами шалунишка? ;3c","keyboard": keyboard, "random_id":0})

      elif text.lower() in  ['неть -. -','нет']:
         vk.method("messages.send",{"user_id":user_id,"message":"Ты... странный... о.О или странная? ","keyboard": keyboardthree,"random_id":0})
      

      else:
            vk.method("messages.send",{"user_id":user_id,"message":"Ой, я ничего не поняла ><` Может ты арт хотел?.. ","keyboard": keyboard,"random_id":0})



def main():
    try:
        for event in longpoll.listen():
            if event.type == VkEventType.MESSAGE_NEW:
                if event.to_me:
                    user_id = event.user_id
                    text = event.text.lower()
                    sender(user_id, text)
    except Exception:
        pass


while True:
   main()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question