Answer the question
In order to leave comments, you need to log in
How to make a repeater bot?
How to make a repeat bot?
In short, I'm making a VK bot, I don't understand how to make it repeat my messages? For example, I use the "!repeat" command and it starts to repeat everything after me. If there is an echo function in the TG, then how to implement it in the VK? Possibly using the listen() function, but when I tried it - errors.
# Импортируем библиотеку vk_api
import vk_api
# Достаём из неё longpoll
from vk_api.longpoll import VkLongPoll, VkEventType
# Создаём переменную для удобства в которой хранится наш токен от группы
token="token"
print('Start.')
# Подключаем токен и longpoll
bh = vk_api.VkApi(token = token)
give = bh.get_api()
longpoll = VkLongPoll(bh)
answer = longpoll.listen
# Создадим функцию для ответа на сообщения в лс группы
def test(id, text):
ts.method('messages.send', {'chat_id' : chatid, 'message' : text, 'random_id': 0})
# Слушаем longpoll(Сообщения)
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
# Чтобы наш бот не слышал и не отвечал на самого себя
if event.from_chat:
# Для того чтобы бот читал все с маленьких букв
message = event.text.lower()
# Получаем id пользователя
chatid = event.chat_id
# Доисторическая логика общения на ифах
# Перед вами структура сообщений на которые бот сможет ответить, elif можно создавать сколько угодно, if и else же могут быть только 1 в данной ситуации.
# if - если, else - иначе(значит бот получил сообщение на которое не вызвана наша функция для ответа)
if message == 'привет':
test(chatid, 'привет')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question