from vk_api.keyboard import VkKeyboardColor, VkKeyboard
from token_0 import token
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
import random
sess = vk_api.VkApi(token= token)
vk = sess.get_api()
longpoll = VkLongPoll(sess)
print('Бот запущен!')
def send(id,text, keyboard=None):
post = {'user_id' : id,
'message' : text,
'random_id' : 0
}
if keyboard != None:
post["keyboard"] = keyboard.get_keyboard()
else:
post = post
sess.method('messages.send',post)
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
try:
msg = event.text.lower()
id = event.user_id
except:
pass
if msg == "Старт" or msg == "Меню":
keyboard = VkKeyboard()
keyboard.add_button("Спонсор",VkKeyboardColor.PRIMARY)
send(id, "Меню", keyboard)
if msg == "Спонсор":
keyboard = VkKeyboard()
keyboard.add_button("Меню",VkKeyboardColor.NEGATIVE)
send(id, "Нету", keyboard)
else:
keyboard = VkKeyboard()
keyboard.add_button("Меню",VkKeyboardColor.POSITIVE)
send(id, "Я вас не понял", keyboard)
import requests
import vk_api
vk_session = vk_api.VkApi(token='токен')
longpoll = vk_api.longpoll.VkLongPoll(vk_session)
vk = vk_session.get_api()
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
if event.text == '1 дом' or event.text == '2 дом': #Если написали заданную фразу
if event.from_user: #Если написали в ЛС
vk.messages.send( #Отправляем сообщение
user_id=event.user_id,
message='просто дом'
)
bot = telebot.TeleBot("TOKEN")
@bot.message_handler(commands=["start"])
def sms(message):
bot.send_message("@durov", "Привет")
@bot.message_handler(content_types='text')
def key_words(message):
if "привет" in message.text.lower():
bot.send_message("@durov", "Привет")
bot.polling()